I have 2 Activities as below:
public class MainActivity extends Activity {
....
profile.login(new onCallback()) {
@Override
public void onResult(int result) {
final Intent i = new Intent(MainActivity.this, DetailActivity.class);
startActivity(i);
}
}
....
}
public class DetailActivity extends Activity {
....
}
Where profile.login run on a AsyncTask and callback when there is a result. Once result received, it will start the 2nd activity.
Here is the trouble steps:
- On MainActivity, press on the login button.
- Press BACK to close the App.
- The app is closed but after a while the 2nd activity popup and immediately follow by a force close.
I trace the life cycle event, logcat shows:
- MainActivity.onClickLogin
- DetailActivity.onCreate started.
- DetailActivity.onCreate ended.
- MainActivity.onDestroy started.
- MainActivity.onDestroy ended.
It is very time-dependent and only happens between "DetailActivity.onCreate ended" and the screen is not shown. Once the DetailActivity screen shown, press Back will not cause MainActivity to destroy. It just destroy the DetailActivity as expected:
- MainActivity.onClickLogin
- DetailActivity.onCreate started.
- DetailActivity.onCreate ended.
- DetailActivity.onDestroy started.
- DetailActivity.onDestroy ended.
My Question is:
Since DetailActivity is already created (onCreated ended) should the back key event sent to DetailActivity and cause it destroy? Why the key is sent to MainActivity?
Any idea how to counter-measure this?
The Android version I am working on is 4.0.x