意图恢复previously暂停活动(从通知调用) [英] Intent to resume a previously paused activity (Called from a Notification)

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

问题描述

我开发一个应用程序,它显示了一个通知给用户。该通知的目的是可以很容易地将用户返回到活动,当用户是在另一个活动。我使用我的应用程序这个code创建并显示该通知。

I'm developing an app which shows a notification to the user. The notification's objective is to make it easy to the user to return to the activity when the user is in another activity. I am using this code in my app to create and show the notification.

                    notification = new Notification(R.drawable.icon,
                            "Notify",
                            System.currentTimeMillis());
                    notification.setLatestEventInfo(this, "App name",
                            "App message",
                            PendingIntent.getActivity(
                                    this, 0,
                                    new Intent(this, Main.class),
                                    PendingIntent.FLAG_CANCEL_CURRENT));
                    notification.flags |= Notification.FLAG_ONGOING_EVENT;
                    nManager.notify(0, notification);

但是,当用户敲击所述通知开始,而不是用户使用之前所述一个相同的活性的新实例,

But when the user taps the notification starts a new instance of the same activity, instead of the one that the user was using before.

我觉得这是与PendingIntent,但我无法找到如何使意图恢复previously暂停创建新实例的活动实例吧。

I think this has something to do with PendingIntent but I can't find how to make that Intent to resume a previously paused instance of the activity instead of creating a new instance.

感谢。

推荐答案

我发现了如何做到这一点。我增加了以下code:

I found out how to do it. I added the following code:

notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

现在我的code是这样的:

Now my code looks like this:

    notification = new Notification(R.drawable.icon,
            "Notify", System.currentTimeMillis());
    notification.setLatestEventInfo(this, "App name",
            "App message", PendingIntent.getActivity(this,
                    0, new Intent(this, Main.class)
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                                    | Intent.FLAG_ACTIVITY_SINGLE_TOP),
                    PendingIntent.FLAG_CANCEL_CURRENT));
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

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

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