You can restart your app in two steps:
- Kill your own process. Use
Process.myPid()
, pass it into
Process.killProcess()
. You might need to add a permission to your manifest (possibly android.permission.KILL_BACKGROUND_PROCESSES
) to get this to work.
- Before you kill your own process, register an Alarm with a pending intent to restart your Activity in the very near future. The second parameter to
alarm.set
is the triggerAtTime
. Setting it to 0 causes the alarm to fire immediately. The example here sets a time to launch the app one second into the future.
The Code goes like this:
AlarmManager alm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alm.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, PendingIntent.getActivity(this, 0, new Intent(this, this.getClass()), 0));