Background:
Suppose an activity a, you need to use the Startactivityforresult method to open activity B. If the launch mode of B is set to Singletask/singletop, then in the instant after B is opened (without waiting for B to return any result), the Onactivityresult method in a is called and receives a Result_ Cancel's request code.
Reason:The startactivityforresult of a can not be used if the open B and open B are different when the two activities work in a task. So, what is a task in Android? By default, activity from the same app exists in the same task. A stack is maintained in each task, which records the activity that was opened and not destroy. At the top of the stack is the current activity in foreground. When you open an app in Home screen, it's the equivalent of a new task being opened. Every time you press the back key, it is equivalent to removing the topmost activity of the task's stack. But the same task stack can also contain activity from different applications (for example, your own app can start another browser's page). When declaring an activity's launch mode as Singletask in Androidmanifest.xml, when the activity is created, it is placed in a new stack and placed on top (that is, placed in a new task). If the activity is already in the stack of a task, only its onnewintent () is called, and OnCreate () is not called. When declaring an activity's launch mode as singleinstance in Androidmanifest.xml, the same as the Singletask mode when creating this activity, It is placed in a new stack and placed on top (that is, in a new task). Unlike the Singletask model, the new task stack will always have only one element, which is the activity itself. If the activity is already in the stack of a task (the stack must have only one element, that is, the activity itself), only its onnewintent () will be called, and OnCreate () will not be called.
Workaround:If your B does need to use the single task's launch Mode, and B does need to return to a some data, try to re-open a in B via StartActivity (Intent Intent). But at this point, you have added the data you want to return in the intent.
Startactivityforresult unable to invoke Singletask activity