[英]Activity not opening from IntentService
我在GcmIntentService extends IntentService
类中获得了推送通知, GcmIntentService extends IntentService
,我试图从此处打开我的ActivityA
。
当应用程序关闭时,它将打开活动,但是如果我的应用程序已在后台运行,则无法打开活动。
Intent intent = new Intent(getApplicationContext(), ActivityA.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
| Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
+ WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+ WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+ WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getApplicationContext().startActivity(intent);
如何通过中断后台应用程序打开ActivityA
?
我使用BroadcastReceiver
来处理来自gcm的消息,并从此类开始一个意图。 试试以下代码:
Intent notificationIntent = new Intent(context, CustomActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(notificationIntent);
它对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.