Tuesday 20 June 2017

How to restart an application programmatically in android


 
The following code snippet shows how to restart an android application after the specified delay
programmatically:


public void restart(int delay) {
    PendingIntent intent = PendingIntent.getActivity(this.getBaseContext(), 0, new Intent(getIntent()), PendingIntent.FLAG_ONE_SHOT);
    AlarmManager manager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    manager.set(AlarmManager.RTC, System.currentTimeMillis() + delay, intent);
    System.exit(2);
}