简体   繁体   English

无法调用 NewIntent

[英]can't call onNewIntent

My program has MainActivity and myService.我的程序有 MainActivity 和 myService。

MainActivity is 'singletop' , and MainActivity overrides onNewIntent class. MainActivity 是'singletop' ,并且 MainActivity 覆盖onNewIntent类。

myService is ' foreground ' Service. myService 是“前台”服务。 It pop up a notification.它弹出一个通知。 The notification has Intent(this,MainActivity.class) in pendingIntent to start MainActivity.通知在pendingIntent 中有Intent(this,MainActivity.class)来启动MainActivity。

My program's flow is我的程序流程是

Launch from icon (start) MainActivity ( startService ) myService ( send broadcast ) broadcast class(start MainActivity)onNewIntent@MainActivity从图标启动(启动)MainActivity( startService )myService( send broadcast )广播class(start MainActivity)onNewIntent@MainActivity

When program is Launched like this flow, onNewIntent is called exactly.当程序像这个流程一样启动时,onNewIntent 被准确地调用。

But when program is Launched from notification, onNewIntent never called.但是当程序从通知启动时,onNewIntent 从未调用过。

Launch from Notification (start) MainActivity (startService) myService (send broadcast) broadcast class(start MainActivity)onNewIntent@MainActivity从通知(start) MainActivity (startService) myService (send broadcast) broadcast class(start MainActivity)onNewIntent@MainActivity

From the guide at http://developer.android.com/guide/topics/manifest/activity-element.html来自http://developer.android.com/guide/topics/manifest/activity-element.html的指南

Similarly, a new instance of a "singleTop" activity may also be created to handle a new intent.类似地,也可以创建“singleTop”活动的新实例来处理新意图。 However, if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call);但是,如果目标任务在其堆栈顶部已经有 Activity 的现有实例,则该实例将接收新的意图(在 onNewIntent() 调用中); a new instance is not created.不会创建新实例。 In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.在其他情况下——例如,如果“singleTop”活动的现有实例在目标任务中,但不在堆栈顶部,或者如果它在堆栈顶部,但不在目标任务中——将创建新实例并将其推送到堆栈上。

Thus onNewIntent is only called if there is an existing instance of the activity at the top of the stack.因此,只有在堆栈顶部存在活动的实例时才会调用 onNewIntent。

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

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