Why is getCallingActivity always returning null?

后端 未结 6 1263
被撕碎了的回忆
被撕碎了的回忆 2021-01-20 19:06

I have a welcome screen that can be started as the first activity in my app, or it can be started by the main activity that the user spends their time in. I want it to act s

6条回答
  •  一生所求
    2021-01-20 19:33

    Everyone seems to be pointing to the same solution but nobody is putting it in clear words. Let me do that.

    It seems like getCallingActivity() returns results inconsistently across different android platforms.

    The issue is caused probably because you are setting the launchMode of your activity as singleInstance or singleTask. Setting it to singleTop or leaving it as the standard one should solve your issue. Of course, changing the mode should not affect your use case so this is at your discretion.

    In case it does affect your use case, you can pass the package name in the extras of the intent to simplify things.

    Note that setting singleInstance or singleTask returns non null results on Lollipop release.

提交回复
热议问题