简体   繁体   English

Android:如果活动已在运行,如何捕获Intent的Extras?

[英]Android: How to catch Intent's Extras if the activity is already running?

I put a notification in the status bar with a PendingIntent (with Extras info) that points to my main app (main activity). 我在状态栏中添加了一个通知,其中包含指向我的主应用程序(主要活动)的PendingIntent(带额外信息)。 When the user clicks the staus bar, the PendingIntent is fired and my app launches and I can read the Extras info in my onCreate() method. 当用户点击staus栏时,会激活PendingIntent并启动我的应用程序,我可以在onCreate()方法中读取Extras信息。 So far so good. 到现在为止还挺好。

But if my app is already running, the PendingIntent simply causes the app to come to the foreground and it does not call any of my methods, so I can't read the content in Extras. 但是如果我的应用程序已经在运行,PendingIntent只会导致应用程序到达前台并且它不会调用我的任何方法,因此我无法读取Extras中的内容。 What can I do? 我能做什么?

Thanks! 谢谢!

It does call a method. 它确实调用了一种方法。

Check out OnNewIntent 看看OnNewIntent

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

相关问题 如何将附加内容传递给已经运行的活动 - How to pass intent with extras to an already running activity 如何将意向额外信息传递到活动和先前活动中的碎片 - How to pass intent extras to activity and frgment inside it from previous activity Android:未在Activity上下文外部通过startActivity()传递Intent Extras - Android: Intent Extras not passed with startActivity() outside Activity context 找不到用于处理Intent的活动android.intent.action.REQUEST_TANGO_PERMISSION(还有其他功能) - No activity found to handle Intent android.intent.action.REQUEST_TANGO_PERMISSION (has extras) android.content.ActivityNotFoundException: 没有找到处理意图的活动 { act=activity2.application1 (有额外的) } - android.content.ActivityNotFoundException: No Activity found to handle Intent { act=activity2.application1 (has extras) } Android - 动态设置intent Extras - Android - Dynamically set intent Extras 如何判断Android中是否存在Intent附加功能? - How do I tell if Intent extras exist in Android? ActivityNotFoundException:没有找到处理 Intent {(有额外功能)} 的活动 - ActivityNotFoundException: No Activity found to handle Intent { (has extras) } 将Extras从Activity传递到Intent会引发NullPointerException - Passing extras from Activity to Intent throws NullPointerException 返回活动时丢失Intent额外内容 - Losing Intent extras when returning to Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM