我需要实现此功能,但我不确定这是否可以在Android上使用。
我们正在运行gcm监听器服务。但是,假设应用程序已打开,并且通知从服务器到达。我需要自动触发活动而不触摸手机屏幕顶部的通知状态栏。
换句话说,一旦通知到达,没有任何用户交互,如果应用程序正在运行,则必须立即触发活动。
我看了一下这个帖子,但这不是我真正需要的。
Intent - if activity is running, bring it to front, else start a new one (from notification)
任何线索或更多信息? THX!
答案 0 :(得分:0)
您可以使用FLAG_ACTIVITY_NEW_TASK标记启动没有其他先前活动的活动。
Context c = getApplicationContext(); // or getContext(), or any other context you can find from the current app
Intent i = new Intent(c, YourActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);