Bring application to front after user clicks on home button

后端 未结 7 908
礼貌的吻别
礼貌的吻别 2020-11-28 09:21

My application is in running mode[foreground] and user clicks on home button, which puts application to background[and still running]. I ha

7条回答
  •  悲&欢浪女
    2020-11-28 09:52

    A combination that works for me is to use:

    Intent bringToForegroundIntent = new Intent(context, RootActivity.class);
    bringToForegroundIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(bringToForegroundIntent);
    

    If you check the logs on the device whenever you start an activity from a launcher icon this is the intent that gets passed to launch the app or move it back to foreground if e.g. user clicked the Home button.

提交回复
热议问题