Did back key destroy an activity?
I have an activity defined as below:
<activity android:name="com.example.ui.HomeActivity"
android:alwaysRetainTaskState="true"/>
A strange thing is that, when running on emulator, and the back key is pressed, the activity was destroyed (I saw onDestroy() called in log). Bu开发者_C百科t when running on my Nexus One phone, and the back key is pressed, the activity is not destroyed (I didn't see onDestroy() called in log).
Could someone tell me why?
Thanks.
When activity is in the background (after pressing Back key) it is always stopped but System can also decide to destroy it (eg. when system resources are low). You can't determine when it will be destroyed.
Activity can also be destroyed by calling finish(). You can determine that by checking isFinishing() status in onPause or onStop callback.
Do not count on onDestroy callback. If system will kill activity it wont be called.
By default, pressing the BACK key finishes (destroys) the current activity and displays the previous activity to the user.
source
精彩评论