通知将应用程序置于最前面,无需更改活动 [英] Notification bring app to front without change activity

查看:59
本文介绍了通知将应用程序置于最前面,无需更改活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个通知,当它单击时将使我的应用程序显示在最前面,但不更改(重新加载或导航)显示的上一个活动.

I want to create notification that when it clicked will bring my app to front but without changing (reload or navigate out) the last activity that was shown.

我尝试过:

setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT))

但是在新的Android 4.3中,该应用程序名列前茅,但它也启动了 MainActivity 的新实例,我不希望这样做.

But in the new Android 4.3 the application brought to front, but its also start a new instance of MainActivity, and I don't want this.

我希望我的应用程序从显示的上一个活动继续执行.
该怎么做?

I want that my app will continue from the last activity that was shown.
How to do that?

推荐答案

您永远不会设置 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT .该标志是由Android在将活动置于最前面时设置的.您设置它无效.

You don't ever set Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT. That flag is set by Android when it brings the activity to the front. You setting it has no effect.

有几种方法可以做您想要的.查看此 answer

There's a few ways to do what you want. Check out this answer

这篇关于通知将应用程序置于最前面,无需更改活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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