StartActivityForResult and startactivityresult of Android
I. Common jump implementation between activities in Android
1) startActivity (Intent intent );
2) startActivityForResult (Intent intent, int requestCode );
The difference is that (2) data can be returned. For example:
Ii. Instructions for use
startActivityForResult(Intent intent, int requestCode)
Start Multiple activityA, B, and C. You can use requestCode to determine the difference;
setResult(resultCode);
When functions A, B, and C are returned, they are differentiated by resultCode;
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); }
Determine data through requestCode and resultCode;
3: onBackPressed () calls setResult ();
OnDestroy () calls setResult ();
The comparison shows that onActivityResult is called after the Activity-B onPause () function and before the Activity-A onRestart () function.
Therefore, setResult () must be called before the onPause () function, while the onStop () or onDestroy () function cannot return data.
Iv. Extension
OnStop () and onDestroy () are used to clear and release resources, rather than transmit data.