How to resume Android Activity programmatically from background

后端 未结 6 1862
情深已故
情深已故 2020-11-30 08:25

Situation:

  1. Let\'s say I have currently working launched application Activity A.
  2. After some time I am pressing \"Home\" button. Application A goes to b
6条回答
  •  無奈伤痛
    2020-11-30 09:10

    If your activities are on different tasks, you can use this to bring the activity's task to foreground:

    ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); 
    activityManager.moveTaskToFront(getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);
    

    You would need android.permission.REORDER_TASKS in order to do so. It works even in Android M, however getting an intent from a service works better in some cases.

提交回复
热议问题