Clarification on Android Activity Lifecycle
Can someone c开发者_如何学JAVAlarify - if in my activity, I leave to call an intent via startActivityForResult (such as take a picture), when users return to my app, what is the entry point for that activity? Is it onCreate, onStart, or onResume?
Thanks!
If the original activity is never stopped, it reenters via onResume(). If it is stopped it reenters via onRestart() -> onStart() -> onResume().
startActivityForResult shouldn't stop the original activity.
Normally, it will be onResume() followed by onActivityResult(). However it's possible, though unlikely, that the calling activity will have been killed at some point while the user worked with the other activity; this happens when the system runs out of memory, at which point it starts killing stuff, starting from the 'most inactive'. In that case, I imagine it would go through onCreate(), onStart(), onResume() and then finally onActivityResult().
The exact callback for onActivityResult() is:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//Your code here
}
精彩评论