简体   繁体   English

当顶部还有另一个活动时,不会调用onNewIntent()

[英]onNewIntent() not being called when there is another activity on top

Seems that onNewIntent() of my MainActivity is not being called when I have another Activity on top of it, if I close the second Activity it does get called just fine, it's like the other Activity which is on top is blocking the messages? 似乎onNewIntent()我的MainActivity的不会被调用时,我有另一个Activity在它的上面,如果我关闭了第二个Activity就不会被调用就好了,它像其他Activity ,其在顶部阻挡了消息? Both Activity s are set to singleTop in the manifest and I set the Intent from a notification: 在清单中,两个Activity都设置为singleTop,我从通知中设置了Intent

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Does anybody know what could be wrong? 有人知道什么地方可能出问题吗?

Thanks! 谢谢!

You have probably already searched google - there are lots of questions on why onNewIntent is not called. 您可能已经搜索过google-关于为什么不调用onNewIntent的问题很多。

It might depend on which android version you are doing tests, but you might try adding Intent.FLAG_ACTIVITY_SINGLE_TOP flag to your intent - even though you have it in your manifest, together with Intent.FLAG_ACTIVITY_CLEAR_TOP . 这可能取决于您要测试的Android版本,但是您可以尝试向Intent.FLAG_ACTIVITY_SINGLE_TOP添加Intent.FLAG_ACTIVITY_SINGLE_TOP标志-即使清单中包含了Intent.FLAG_ACTIVITY_CLEAR_TOP

intent.setFlag(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlag(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

this will remove activities above you activity which you want to launch. 这会删除您要启动的活动之上的活动。

But if your intent is to keep two activities alive, and switch between them, then look into android:taskAffinity and FLAG_ACTIVITY_NEW_TASK . 但是,如果你的目的是为了保持两种活动活着,并在它们之间进行切换,然后寻找到安卓taskAffinityFLAG_ACTIVITY_NEW_TASK

Verify that the correct launch mode is set for the Activity receiving the Intent. 验证是否为接收意图的活动设置了正确的启动模式。 Set launchMode to " singleTop " in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent) . 设置launchMode为“ singleTop在他们的包”,或者,如果客户端使用的FLAG_ACTIVITY_SINGLE_TOP打电话时标志startActivity(Intent)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM