Android, Long, Updated, Utils

[U] Android – tips & tricks


Brief written observations which are important to remember and use, usually with an explanation and examples.

Tips & Tricks

Regarding Android:

  1. Don’t use  @android:color/transparent in gradientmore
  2. @IntDef instead enum (cool with resources) – more
  3. If in the code we don’t use special methods from layout better is keep a reference to ViewGroup instead e.g. to FrameLayout or LinearLayout – more
  4. Use reusable resources & styles, use parent style – more, more
  5. Include layoutsmore
  6. Multiple fragments against large nested activitymore
  7. Use formatted strings in XML two%d and getString method than two+”2″
  8. If you need only primitive data types use SparseArray than ArrayMap to avoid unnecessary autoboxing – more

Regarding Java:

  1. Don’t catch Throwablemore
  2. Use “two” + String.valueOf(2) than “two” + 2. //good
  3. Use “two” + Integer.toString(2); // good
  4. Use String.format(“two”%d”,2); //even better
  5. Don’t use == with strings, use equal.
  6. Simplify literal boolean values – return expression.
  7. Simplify literal boolean values –  if (expression) than if (expression == true).
  8. Use thread.start than

Regarding Clean Code:

  1. Remove all unused code.
  2. Reduce complexity (for, if in one method).
  3. Avoid nested control flow.
  4. Split big classes and methods.
  5. Avoid too many parameters.
  6. Avoid complex conditions.
  7. Hide constructor each utility class.
  8. Override for reason.
  9. Use meaningful names.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s