Scriptico

How to restart an application in android programmatically

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()), getIntent().getFlags());
	AlarmManager manager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
	manager.set(AlarmManager.RTC, System.currentTimeMillis() + delay, intent);
	System.exit(2);
}

Related API:
PendingIntent
AlarmManager

Category: Android, Android, Java, Mobile

Tagged:

Comments are closed.