重复MainActivity当从通知进入 [英] Duplicate MainActivity When Enter From Notification

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

问题描述

    Intent intent = new Intent(_context, MainActivity.class);
    PendingIntent activity = PendingIntent.getActivity(_context, 0, intent, 0);
    notification.contentIntent = activity;

从通知进入MainActivity如果MainActivity已经打开,因此我需要出口的两倍。这是一个falg问题,我该怎么办?

Enter MainActivity from notification if MainActivity is already opened, thus I need exit twice. Is this a falg problem, what should I do?

推荐答案

是的,它是...你要这个标志添加到您的待处理的意图。

Yes It is.. You have to add this flag to your pending Intent.

Intent intent = new Intent(_context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP|   Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent activity = PendingIntent.getActivity(_context, 0, intent, 0);

在这里拍的形式,

Taken form here,

http://stackoverflow.com/a/7308940/603744

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

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