如何从通知状态栏打开最近的活动? [英] How to open last activity from notification status bar?

查看:148
本文介绍了如何从通知状态栏打开最近的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开上次启动活动通过点击状态栏的通知。假设我开始一个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.

这篇关于如何从通知状态栏打开最近的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆