Amelia@Amazon avatar image
Amelia@Amazon posted

Preventing context related crashes during activity transitions


Apps crashing when attempting to bind to a context of a null object due to improperly handling an Activity transition.


Since Android 5.0 uses ART for Ahead of Time Compilation instead of JIT compilation done earlier in Dalvik, it's likely that subtle timings between activity transfers cause issues with bringing up new activities prior to calling finish().

We have seen applications that have tried to implement new activities off of a preexisting context and then calling finish() explicitly. This has led to unpredictable results and crashing under the Android Runtime in Lollipop.

The proper solution here would be to bind your context to getApplicationContext(), rather than an activity context within a transition, as there is no guarantee as to the activity object still being in memory throughout the transition. As getApplicationContext() is bound to your app's process, which is more predictably present in this case.

Keywords: Context, Crashes, JIT, ART, Dalvik


10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.



brizzlebrazzle contributed to this article