Skip to content Skip to sidebar Skip to footer

Intentservice Prevents Activity From Destroying

As far as i know, when i rotate the screen, the activity gets destroyed and recreated. In the following scenario, it looks like this is not always the case. So the question is: Is

Solution 1:

Run it through the debugger with breakpoints in your code and check the id of "this" in the ResultReceiver. It's keeping a local copy of "this" which points to your previous activity, where int mTestVar == 1. The current active Activity is a whole different object, with it's own copy of mTestVar == 2. This is a memory leak.

To answer your question more concisely: Android "destroyed" you activity, but you kept a reference to the Activity in your callback preventing it from being garbage collected. If you want something to "live" across multiple activities you should use a service to store that state (keep in mind a service is NOT a separate thread and should not be used like one).

A side note: When checking variables and general purpose logging it's best to use Log.v/e/i etc. You can filter them at the command line with adb logcat mytag:V *:S or use the logcat built into eclipse.

Post a Comment for "Intentservice Prevents Activity From Destroying"