Call startActivityForResult in a non-activity class,
For this question, I spent the afternoon not saying that I don't know how to call it, but that I used a seemingly correct call method, which is actually a pitfall.
I used the following method:
((Activity) mContext).startActivityForResult
This method is correct and context must be converted to Activity.
However, because I used it in a special scenario, the onActivityResult of the activity is not called back.
Next let's talk about my scenarios:
I created a DialogActivity in MainActivity and called the start () method of utils in DialogActivity. The statement in this method is (Activity) mContext ). startActivityForResult, while onActivityResult in DialogActivity is not called back.
After debugging for half a day, we found that the context of the start method of DialogActivity that is passed into utils belongs to MainActivity, because DialogActivity is started in MainActivity. In this case, MainActivity calls startActivityForResult. The onActivityResult of MainAcvtivity will be called back, but the result will not.
Originally, there was a DialogActivity between MainAcvtivity and the Activity to be started, and the returned result was returned to DialogActivity. Therefore, the onActivityResult of MainActivity will not be called back.
Solution: Do not upload context to call or upload activity
CONCLUSION: (Activity) mContext). startActivityForResult, which Activity the context belongs to, is the activity that calls the method and wants onActivityResult to get the callback. The two activities cannot be separated by other activities.
Respect labor results, reprinted please indicate the source: http://www.cnblogs.com/tangZH/p/8575836.html