How do I programmatically “restart” an Android app?

后端 未结 26 2016
小鲜肉
小鲜肉 2020-11-22 12:42

Firstly, I know that one should not really kill/restart an application on Android. In my use case, I want to factory-reset my application in a specific case where a server s

26条回答
  •  太阳男子
    2020-11-22 13:16

    I had to add a Handler to delay the exit:

     mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 200, mPendingIntent);
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Runtime.getRuntime().exit(0);
                }
            }, 100);
    

提交回复
热议问题