onActivityResult do not fire if launch mode of activity is singleInstance

前端 未结 5 1862
無奈伤痛
無奈伤痛 2020-12-02 20:52

I have an Activity which is basically my main activity and its launch mode is single instance. But because of singleInstance, the onActivityResult() callback do

5条回答
  •  半阙折子戏
    2020-12-02 21:24

    Android Source Code

    Check "ActivityStarter.computeLaunchingTaskFlags()" method:

                } else if (mSourceRecord.launchMode == LAUNCH_SINGLE_INSTANCE) {
                // The original activity who is starting us is running as a single
                // instance...  this new activity it is starting must go on its
                // own task.
                mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK;
    

    That's the reason why NEW_TASK flag is added when your original activity with single instance launch mode.

    More Source Code

    Check "ActivityStarter.sendNewTaskResultRequestIfNeeded()" method:

            if (sourceStack != null && (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
            // For whatever reason this activity is being launched into a new task...
            // yet the caller has requested a result back.  Well, that is pretty messed up,
            // so instead immediately send back a cancel and let the new task continue launched
            // as normal without a dependency on its originator.
            Slog.w(TAG, "Activity is launching as a new task, so cancelling activity result.");
            sourceStack.sendActivityResultLocked(-1 /* callingUid */, mStartActivity.resultTo,
                    mStartActivity.resultWho, mStartActivity.requestCode, RESULT_CANCELED,
                    null /* data */);
    

    That's the reason why FLAG_ACTIVITY_NEW_TASK always immediately return RESULT_CANCELED.

提交回复
热议问题