从通知恢复活动 [英] resuming an activity from a notification

查看:153
本文介绍了从通知恢复活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在状态栏的通知我的应用程序:

I have a notification in the status bar for my app:

    Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());

    Intent notificationIntent = new Intent(this.parent, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this.parent, 0, notificationIntent, 0);

    ...

    notification.flags = Notification.FLAG_ONGOING_EVENT;        
    mNotificationManager.notify(NOTIFICATION_ID, notification);

这样做的问题是,当你preSS从应用程序的主页按钮在从状态栏访问列表中的通知(将其推到背景),那么preSS,它启动一个全新副本的活性。所有我想要做的是恢复应用程序(比如当PSS上的应用程序的图标,home键和preSS你很久$ P $)。有没有一种方法创建一个意向要做到这一点?

The problem with this is that when you press the home button from the app (pushing it to the background) then press on the notification in the list accessed from the status bar, it starts a fresh copy of the activity. All I want to do is resume the app (like when you longpress the home button and press on the app's icon). Is there a way of creating an Intent to do this?

推荐答案

我已经改变解决了这个问题,我的活动 launchMode singleTask 在AndroidManifest.xml文件。

I've solved this issue by changing the launchMode of my activity to singleTask in the androidManifest.xml file.

此属性的默认值为标准,它允许任意数量的实例来运行。

The default value for this property is standard, which allows any number of instances to run.

singleTask和singleInstance活动只能开始的任务。它们总是在活动堆的根。此外,该设备可以容纳的活性只有一个实例在一个时间 - 只有一个这样的任务。 [...]

"singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task. [...]

在singleTask和singleInstance模式也各不相同只在一个方面:一个singleTask活动允许的其他活动是其任务的一部分。它总是在其工作的根本,但其他活动(不一定是标准​​和singleTop的活动),可以发射到该任务。阿singleInstance活性,另一方面,允许没有其他活动是其任务的一部分。它在任务的唯一活动。如果它开始另一个活动,该活动被分配给一个不同的任务 - 仿佛FLAG_ACTIVITY_NEW_TASK是在意图。

The "singleTask" and "singleInstance" modes also differ from each other in only one respect: A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.

您可以找到的Andr​​oid开发者指南

我希望这有助于

这篇关于从通知恢复活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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