如何从通知状态栏打开最近的活动?

编程入门 行业动态 更新时间:2024-10-26 06:31:03
本文介绍了如何从通知状态栏打开最近的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想打开上次启动活动通过点击状态栏的通知。假设我开始一个Activity A(我的应用程序的主要活动),这一活动将发送通知给通知状态栏。活动A也打开了一个活动B和B打开另一个活动C.从C I preSS home键。现在我想再次去我的应用程序,所以从通知栏我点击的通知(这是通过发送A)。在这里通知应该开始活动C,因为它是上次打开。

I want to open last started activity by tapping on the notification in status bar. Suppose I start an Activity A (main activity of my app), this activity sends a notification to notification status bar. activity A also opens an activity B and B opens another activity C. From C i press home button. Now i want to go again to my app so from notification bar i tap on notification (which was sent by A). Here the notification should start activity C because it was last opened.

我没有搜索这个,但没有找到合适的答案。先谢谢了。

I did search on this but didn't find proper answer. Thanks in advance.

推荐答案

几天就回来我得到了我的问题非常非常简单的解决方案。而不是通过 recentTasks 迭代,并把我们的任务,然后得到的 baseIntent 通过它,我们可以做简单的事情,如下所示:

Few days back I got very very simple solution for my problem. Instead of iterating through recentTasks and getting our task and then getting baseIntent through it, we can do simple thing as follows:

Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.setAction(Intent.ACTION_MAIN);

baseIntent 包含相同的参数上面意图有。对因此而不是 baseIntent 从 recentTasks 霎那,这是相当不错的使用上面code。

baseIntent contains the same parameters as above Intent has. Hence instead of grabbing baseIntent from recentTasks, it's quite good to use above code.

本 notificationIntent 将被传递给 pendingIntent 继续使用。

This notificationIntent will then be passed to pendingIntent for further use.

提供: MainActivity 是,当我们推出我们的应用程序和第一个活动在AndroidManifest.xml中必须包含 IntentFilters 的 CATEGORY_LAUNCHER 和 ACTION_MAIN 。

Provided: MainActivity is the very first activity when we launch our app and in AndroidManifest.xml it must contain IntentFilters of CATEGORY_LAUNCHER and ACTION_MAIN.

更多推荐

如何从通知状态栏打开最近的活动?

本文发布于:2023-11-27 12:04:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637997.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态栏   通知

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!