Android的:如何以聚焦属于不同的任务后台的活动? [英] Android: How to give focus to a background Activity belonging to a different task?

查看:96
本文介绍了Android的:如何以聚焦属于不同的任务后台的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设用户已经开始了我的应用程序,然后关闭使用的浏览器(所以我们有2台任务运行)。过了一会儿,事情发生在我的应用程序需要用户的关注,所以它张贴通知以通知用户。有没有办法从背景带给我的应用程序的任务(和堆栈顶部的活动)出来的时候用户点击我的通知?

Say that the user has started my App and then switched off to use the Browser (so we have 2 sets of Tasks running). After a while, something happens to my app that requires the user's attention, so it posts a notification to notify the user. Is there a way to bring my App's task (and the Activity on top of the stack) out from the background when user clicks on my notification?

推荐答案

在您的通知你打电话的意图,开始您的应用程序,如果你确保它具有以下标志那么它将被带到前面,而不是创建另一个实例:

In your notification you call an intent to start your app, if you ensure it has the following flags then it will be brought to front rather than creating another instance:

 Intent contentIntent = new Intent(this, ABC.class);
 contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | INTENT.FLAG_ACTIVITY_SINGLE_TOP);

这篇关于Android的:如何以聚焦属于不同的任务后台的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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