App Development

Android Development Tidbits // No. 7

Tips from your friendly WillowTree Android Developer. Enjoy!

Tidbit One If sending data to an activity via Intent, be careful where you get your Intent data from if the started activity has launchMode= “singleTask”. The Activity will be brought to the top of the stack if it was already created. onCreate will not be called and getExtras() will return null in this case because it will have the same Intent it started with when it was initially launched. onNewIntent, however, will be called which should have the data you sent. -Tidbit Contributor, Brandon Carter

Tidbit Two Rxjava’s retry When is a good solution when a webserver does something odd like return a 200 for an expired token error and you can’t use okhttp’s authenticator. Check out Dan Lew’s blog for a more detailed explanation on retryWhen: -Tidbit Contributor, Evan Tatarka

Tidbit Three Do you need to hide the keyboard automatically when there is an edittext in a dialog?dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); -Tidbit Contributor, Evan Tatarka

Tidbit Four If you are overriding onCreateDialog instead of onCreateView in a DialogFragment, onViewCreated will not be called. -Tidbit Contributor, Evan Tatarka

Tidbit Five BuildConfig.DEBUG in your library project != BuildConfig.DEBUG in your application project. Since the IDE builds a “release” version of your lib when it’s used in your application, even if your application is signed with the debug keystore, the library is not. -Tidbit Contributor, Austen Lux

Tidbit Six adb longcat is equivalent to adb logcat -v long -Tidbit Contributor, Evan Tatarka

Tidbit Seven Be careful about showing dialog fragments as the result of an API call, it might happen after your activity’s state has been saved and it will throw an exception. One solution: only show between onResume() and onPause(). Otherwise, wait till the next onResume(). -Tidbit Contributor, Evan Tatarka

Tidbit Eight If you get an incomprehensive error message like:

A problem occurred configuring project ':ui'.
[Step 1/2] > Failed to notify project evaluation listener.
[Step 1/2] >[Ljava/lang/Object;

Most likely you need to update some plugin or dependency version to latest, in my case it was Kotlin gradle plugin. Do:

./gradlew build --stacktrace

it will give you a full error log and a hint at what exactly needs to be updated. -Tidbit Contributor, Tatyana Casino

Tidbit Nine Want to easily add Version Name and Version Code to your build outputs? Use: archivesBaseName = "halogen-$versionName-$versionCode" in your app modules build.gradle in the defaultConfig. -Tidbit Contributor, Eric Richardson

Tidbit Ten Want to also clear out unwanted unaligned .apks that you keep raging over on your CI server? Use:

applicationVariants.all { variant ->
   variant.assemble.doLast {
       variant.outputs.each { output ->
           File unaligned = output.packageApplication.outputFile;
           File aligned = output.outputFile
           if (!unaligned.getName().equalsIgnoreCase(aligned.getName())) {
               println "deleting " + unaligned.getName()

and you’ll be left with only the zipAligned apks. Yay for less clutter. -Tidbit Contributor, Eric Richardson

Moving from Monolith to Microservices Architecture

When a client decides to move from a monolith platform to microservice architecture,...

Read the article