Pentium10 Pentium10 - 2 months ago 19
Android Question

Programmatically relaunch/recreate an activity?

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?


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.