Archive for the ‘Android’ Category

Screen Rotation in a Dialog Themed Activity

Thursday, September 1st, 2011

One of the apps I am writing uses an Activity that is themed with the @android:style/Theme.Dialog theme. This means that when the user enters the new dialog-themed activity the previous activity can still be seen in the background of the current activity. Not only can the user see the activity in the background but it still receives Activity lifecycle events before the Dialog-themed activity in front of it.

This has implications in screen rotation and other configuration changes: I had some code that starts my dialog-themed activity when a certain condition was met in the onResume() callback for the background activity. Every time I did a screen rotation the condition was met and created a new activity with a startActivity() call. This caused an activity/memory leak and some very confusing behavior.

I solved it by adding the FLAG_ACTIVITY_REORDER_TO_FRONT to the intent I used to start the activity. Now it will re-use the dialog-themed activity on screen rotation rather than trying to create a new one every time.

Android Sources

Wednesday, March 16th, 2011

There are several posts online about how to obtain the Android source code for viewing in Eclipse. This one is great, but it hasn’t been updated in a long time. As a result, I thought I’d take the time to build .zip files using the tools on that page for the more modern Android SDKs. Here are the .zips for your consumption:

All of these were built to be attached to the android.jar that exists in your Eclipse project, so you don’t need to unzip them at all, simply attach them to the JAR following the process on the page linked above.