Single Instance : Launch Mode of Launcher Activity

主宰稳场 提交于 2019-11-30 16:02:53

Bingo! Finally an explanation for this strange behaviour!

You said you start SecondActivity from MainActivity like this:

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivityForResult(intent, REQUEST_CODE_NOTIFY);

When using startActivityForResult(), the Activity that is launched must run in the same task as the Activity that expects the result (ie: the launching Activity). Because of that, Android is ignoring the launchMode of MainActivity and starting SecondActivity in the same task.

You have created a conflict that isn't documented. To solve your problem you need to decide what you want. You cannot have a singleInstance Activity that calls startActivityForResult(). Either choose another mechanism to communicate between SecondActivity and MainActivity or remove the special launch mode for MainActivity.

Why do you want MainActivity to be singleInstance anyway? Is there a reason for this?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!