protected Dialog onCreateDialog(int id) {
...
AlertDialog.Builder adb = new AlertDialog.Builder(this);
...
mydialog = adb.create();
...
}
But onCreateDialog runs after onCreate.
protected Dialog onCreateDialog(int id) {
...
AlertDialog.Builder adb = new AlertDialog.Builder(this);
...
mydialog = adb.create();
...
}
But onCreateDialog runs after onCreate.
If you want to be backwards compatible, you do it as follows.
The nonConf objects will survive all configuration changes (but not real stops of your app). Also, the isConfigChange flag tells you reliably if your activity is going to be re-created immediately or not. Thus, you can cancel/detach tasks or handle other resources adequately based on this information.
Edit: Please note that if
onDestroy()
is called then you can rely on theisConfigChange
flag. Also, if Android is processing a configuration change thenonDestroy()
will be called. However, if Android is about to end your activity then the call to onDestroy() is optional because Android considers your activity to be killable right after it callsonPause()
(pre-Honeycomb) oronStop()
(Honeycomb and beyond). That's not a problem though, because if your activity is going to be killed, the state of your numerous objects isn't interesting to anyone anymore. However, if you want to be friendly, this is one more aspect to consider regarding the decision what to put intoonPause()
andonStop()
.Hope this helps.