Bring application back to front

前端 未结 3 1861
轮回少年
轮回少年 2021-02-19 14:18

My application is a timer with alarm type app. When the timer expires i would like to bring the app\'s main activity back into view, if the user has navigated away, but the app

3条回答
  •  一生所求
    2021-02-19 15:19

    You should put your timer in a Service, that way you're assured that Android won't kill your application while it's in background. (You can put your whole MyCount class in a service).

    From the service you can always bring your application (Activity) to the front:

    Intent intent = new Intent(getBaseContext(), TimerActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    startActivity(intent);
    

提交回复
热议问题