Close application and launch home screen on Android

后端 未结 21 2154
我在风中等你
我在风中等你 2020-11-22 07:33

I have two different activities. The first launches the second one. In the second activity, I call System.exit(0) in order to force the application to close, bu

21条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 08:23

    Try the following. It works for me.

    ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List taskInfo = am.getRunningTasks(1); 
    ComponentName componentInfo = taskInfo.get(0).topActivity;
    am.restartPackage(componentInfo.getPackageName());
    

提交回复
热议问题