How to resume Android Activity programmatically from background

后端 未结 6 1865
情深已故
情深已故 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 08:48

    Just establish a Service, doing whatever you want it to in the background. Or even better: Do something in the background, listen to it with a listener, bind a Service as soon as the event you waited for occurs (timer etc). Now that you are in the Service, you just call the Activity that should be on foreground like you would from anywhere else:

    Intent i = new Intent(MyService.this, MyActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    MyService.this.startActivity(i);
    

提交回复
热议问题