Android Tips and Tricks-gsmprix

SaveSavedRemoved 2
Deal Score+4
Deal Score+4
  1. Always use android:textSize as SP (scale-independent pixels) instead of DP or DiP (density-independent pixels).  If we will use Sp for textSize, then it will auto resize as per the device font size. So when the user will change the device font size to Small or Large, then the text sizes will auto adjust. But if we use Dp or Dip, then the text size will remain unchanged as per the font change.
  2. Always use the default Android Design structure instead of using any MVC or MVP or any other customized design structure. Because, if you will use the default one, then you can easily override any updated method provided by Android in the default Activity or Fragment from the Superclass. You don’t have to worry about writing any extra method and controller to link with the Activity to make it workable. The default design will be clean, but the customized design will not so clean and might be a problem for upcoming developers who are going to work on your project. So always default is simple, clean, and best.
  3.  Always try to create two layouts for each app. One is for a portrait in a res-layout folder and the other is one for landscape in a res-layout-land folder. It will help you to show the app in both orientations.
  4. Try to check “Not Equal To Null” for each object whether it is static or dynamic. For example, if ‘x’ is an object and you are trying to get data from ‘x’ then before doing anything fist check
If(x != null){ //get data from x like x.getData() .. }
It will help you to avoid NullPointerException 5) If you have used any AlertDialog or Dialog in any Activity and defining globally, i.e in the Class level, then make sure you have dismissed the dialog on the onStop() method of that Activity or Fragment. It will help you to avoid BadTokenException.

We will be happy to hear your thoughts

Leave a reply

Gsmprix | Mobile Phone Reviews, Mobile Specifications
Compare items
  • Total (0)