Programmatically relaunch/recreate an activity?


Question

After I do some change in my database, that involves significant change in my views, I would like to redraw, re-execute onCreate.

How is that possible?

1
106
3/21/2010 11:51:41 AM

Accepted Answer

UPDATE: Android SDK 11 added a recreate() method to activities.


I've done that by simply reusing the intent that started the activity. Define an intent starterIntent in your class and assign it in onCreate() using starterIntent = getIntent();. Then when you want to restart the activity, call finish(); startActivity(starterIntent);

It isn't a very elegant solution, but it's a simple way to restart your activity and force it to reload everything.

109
5/12/2019 12:16:55 PM

Call the recreate method of the activity.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon