簡體   English   中英

活動未從IntentService打開

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM