Resolves an issue that passes the request code when the activity is started in fragment:
The first thing to point out is that fragment has startactivityforresult methods, and there are startactivityforresult methods in activity: the difference between the two is:
The Startactivityforresult method in fragment:
The Startactivityforresult method in Fragmentactivity:
It can be seen from the official explanation that the Startactivityforresult method in fragment is called activity, The Startactivityforresult method in Fragmentactivity is to rewrite the startactivityforresult in the activity. So we call fragment's Startactivityforresult method, and when the activated activity returns, the Onactivityresult method in Fragmentactivity is called but cannot get the correct request code, If you call the Startactivityforresult method in Fragmentactivity, the fragment Onactivityresult method is not invoked when the activated activity returns.
Summarize:
If you want to start activity in fragment and ask for results, there are two result scenarios:
First: Call the Startactivityforresult method of fragment, and then process the returned request in fragment's Onactivityresult method.
The second is to obtain the Fragmentactivity object where the fragment is located in fragment through the Getactivity () method. Call the Activity object's Startactivityforresult method to start the activity, and then process the returned request in the Fragmentactivity Onactivityresult method.
To resolve the problem of passing the request code when the activity is started in fragment