tags:

views:

252

answers:

4

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?

+2  A: 

You can't. Worst-case, call setContentView() again. Better (for CPU time) is to update the existing widgets in place.

CommonsWare
A: 

If this is your problem, you should probably implement another way to do the view filling in your Activity. Instead of re running onCreate() you should make it so onCreate() calls your filling method with some argument. When the data changes, the filling method should get called with another argument.

MrSnowflake
+1  A: 

Hmm, maybe this isn't a good way of doing things (according to CommonsWare's comment), but the way I've handled that situation in my game is simply reusing the intent that started the activity. Define an intent starterIntent at the top of your class and in the onCreate method use starterIntent = getIntent() to retrieve the Intent that started this activity. Then when you want to restart the activity, call startActivity(starterIntent); finish();

Like I wrote above, perhaps this isn't a very elegant solution and wastes processing time, but it's a simple way to restart your activity and force it to reload everything.

Steve H
actually i think when the device orientation changes the activity's oncreate is called in a similar way.. so i don't mind doing this.startActivity(getIntent());finish();
Raja
A: 

From a widget when I relaunch an activity which resides in home screen after pressing home button, none of the events of that activity is getting called in HTC hero. It is working as expected in 1.5 emulator. How to solve this issue?

Linto
You should ask this as your own question, rather than posting it as an answer to someone else's question. Also, when writing your question, try to give more detail about what you've tried, e.g. what events you're expecting to see.
Steve H