Android Performance

Android Tips Round-Up, Part 3

Word count: 466Reading time: 2 min
2015/03/15
loading

Here’s the third round-up of Android tips I’ve been posting.

UrlQuerySanitizer - Sanitize URLs with this handy utility.

Fragment.setArguments - Since you can’t use a Fragment constructor w/ parameters this is the second best thing. Arguments set before creation last throughout the entire Fragment’s lifecycle (even if it’s destroyed/recreated due to a configuration change).

DialogFragment.setShowsDialog() - Neat trick - DialogFragments can act like normal Fragments! That way you can have the same Fragment do double-duty. I usually create a third View generation method that both onCreateView() and onCreateDialog() call into when creating a dual-purpose Fragment.

FragmentManager.enableDebugLogging() - Help when you need it when figuring out Fragments.

LocalBroadcastManager - Safer than global broadcasts. Simple and quick. Event buses like otto may make more sense for your use case though.

PhoneNumberUtils.formatNumber() - Let someone else figure out this problem for you.

Region.op() - I found this useful for comparing two generic areas before rendering. If I’ve got two Paths, do they overlap? I can figure that out with this method.

Application.registerActivityLifecycleCallbacks - Though lacking documentation I feel this is self-evident. Just a handy tool.

versionNameSuffix - This gradle setting lets you modify the versionName field in your manifest based on different build types. For example, I would setup my debug build type to end in “-SNAPSHOT”; that way you can easily tell if you’re on a debug build or release build.

CursorJoiner - If you’re using a single database then a join in SQL is the natural solution, but what if you’ve received data from two separate ContentProviders? In that case CursorJoiner can be helpful.

Genymotion - A much faster Android emulator. I use it all day.

-nodpi - Most qualifiers (-mdpi, -hdpi, -xhdpi, etc.) automatically scale assets/dimensions if you’re on a device that isn’t explicitly defined. Sometimes you just want something consistent though; in that case use -nodpi.

BroadcastRecevier.setDebugUnregister() - Another handy debugging tool.

Activity.recreate() - Forces an Activity to recreate itself for whatever reason.

PackageManager.checkSignatures() - You can use this to find out if two apps (presumably your own) are installed at the same time. Without checking signatures someone could imitate your app easily by just using the same package name.

More

  1. Part 1
  2. Part 2
  3. Part 3
  4. Part 4
  5. Part 5

Original Article: http://blog.danlew.net/2014/04/28/android-tips-round-up-part-3/

About Me && Blog

Below is my personal intro and related links. I look forward to exchanging ideas with fellow professionals. “When three walk together, one can always be my teacher!”

  1. Blogger Intro
  2. Blog Content Navigation: A guide for my blog content.
  3. Curated Excellent Blog Articles - Android Performance Optimization Must-Knows
  4. Android Performance Optimization Knowledge Planet

One walks faster alone, but a group walks further together.

Scan WeChat QR Code

CATALOG
  1. 1. More
  • About Me && Blog