Pressing back button in ActivityGroup causes it to pause, and then continue shutting down the next t
Posted
by synic
on Stack Overflow
See other posts from Stack Overflow
or by synic
Published on 2010-05-13T05:37:19Z
Indexed on
2010/05/13
5:44 UTC
Read the original article
Hit count: 389
android
Pressing the back button causes onPause to be called, and the app stays paused until it is re-launched by clicking on the icon, at which point, onDestroy gets called, and the main activity continues to shut down.
Simple class to demonstrate. Note, as far as I can tell, this only happens on the Nexus One. I can't reproduce it in the emulator or on my Droid.
package com.vimtips.testshutdown;
import android.app.ActivityGroup;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
public class MainActivity extends ActivityGroup {
private static final String TAG = "MainActivity";
private int counter = 3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {
if(counter-- > 0) return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onPause() {
super.onPause();
Log.d(TAG, "onPause called");
}
@Override
public void onDestroy() {
super.onDestroy();
if(isFinishing()) {
Log.d(TAG, "Shutting down");
}
}
}
And here's the log:
I/ActivityManager( 132): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10100000 cmp=com.vimtips.testshutdown/.MainActivity }
I/ActivityManager( 132): Displayed activity com.vimtips.testshutdown/.MainActivity: 305 ms (total 305 ms)
D/MainActivity( 1393): onPause called
I/ActivityManager( 132): Displayed activity com.vimtips.testshutdown/.MainActivity: 302 ms (total 302 ms)
D/MainActivity( 1393): Shutting down
This doesn't appear to happen on a normal Activity, just an Activity group, though looking at Android's sourcecode, I can't figure out why. It's causing some serious problems with my app.
Anyone know why this would happen?
© Stack Overflow or respective owner