how do I restart an activity in android?

Ephraim picture Ephraim · Apr 3, 2011 · Viewed 38.1k times · Source

in an app that I am writing, there is a part of it that allows you to change a curtain setting. the problem is, that this setting won't take effect until the activity is recreated. is there a way to tell the app to restart using the onResume() method (hopefully allowing it to save everything in the onSaveInstanceState())?

Answer

Ted Hopp picture Ted Hopp · Apr 3, 2011

This has been posted before:

Intent intent = getIntent();
finish();
startActivity(intent);

As of API level 11, you can also just call an activity's recreate() method. Not only is this cleaner because it is less code, it avoids issues that may arise if your activity was launched by an implicit intent.