Reputation: 26291
I need to restart the application from PreferenceActivity
on preference changed. I tried:
@Override
public void onSharedPreferenceChanged(SharedPreferences pref, String key) {
System.exit(2);
}
but after restart settings are not saved. Any ideas of how to restart the app with preferences are saved?
Thanks in advance
Upvotes: 1
Views: 2640
Reputation: 2576
If it's still useful for you: restart an app with AlarmManager:
AlarmManager alm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alm.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, PendingIntent.getActivity(this, 0, new Intent(this, myActivity.class), 0));
Process.killProcess(Process.myPid());
Upvotes: 1
Reputation: 1036
Instead of a System.exit(2); I would try a
this.finish();
finish() is the call to stop the activity.
to start an activity you need an intent object
Intent screenToBeShown = new Intent(myactivity.this, whateveractivityyouwant.class);
startActivity(screenToBeShown);
Hope this helps.
Upvotes: 3