Bring task to front on android.intent.action.USER_PRESENT

前端 未结 2 2000
后悔当初
后悔当初 2020-12-10 19:11

BACKGROUND
I have a task (i.e. app) with multiple activities.

QUESTION
How do I bring a task to the front w/o re-ordering

2条回答
  •  一向
    一向 (楼主)
    2020-12-10 19:48

    Ok, I was able to get this to work by adding a static global variable in my main activity (activity_A). In onCreate I set isRunning = true, and onDestory = false. Then in my IntentReceiver class I check the isRunning to determine which activity to start:

                :
        if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
            if (GlobalVariables.isRunning) {
                activityClass = BringToFront.class;
            } else {
                activityClass = activity_A.class;
            }
        } else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            activityClass = activity_A.class;
        }
                :
    

提交回复
热议问题