Is it a good practice to reload an activity in Android?
What would be the best way to do it? this.finish
and then this.startActivity
with the activity intent?
Is it a good practice to reload an activity in Android?
What would be the best way to do it? this.finish
and then this.startActivity
with the activity intent?
I don't think that's a good idea... it'd be better to implement a cleaner method. For instance, if your activity holds a form, the cleaner method could just clear each widget in the form and delete all temporary data. I guess that's what you want: restore the activity to its initial state.
in some cases it's the best practice in other it's not a good idea it's context driven if you chose to do so using the falowing is the best way to pass from an activity to her sons :
Intent i = new Intent(myCurrentActivityName.this,activityIWishToRun.class);
startActivityForResult(i, GlobalDataStore.STATIC_INTEGER_VALUE);
the thing is whenever you finish() from activityIWishToRun you return to your a living activity
Android includes a process management system which handles the creation and destruction of activities which largely negates any benefit you'd see from manually restarting an activity. You can see more information about it at http://developer.android.com/guide/topics/fundamentals.html#procthread
What is good practice though is to ensure that your onPause and onStop methods release any resources which you don't need to hold on to and use onLowMemory (http://developer.android.com/reference/android/app/Activity.html#onLowMemory()) to reduce your activities needs to the absolute minimum.
I want to refresh the activity then I get a new location or random number (nothing to do with the best way of closing etc..)
It does it anyway when the orientation is changed so why not have a method to run?
Its probably obvious but I cannot find it.....
After experimenting with this for a while I've found no unexpected consequences of restarting an activity. Also, I believe this is very similar to what Android does by default when the orientation changes, so I don't see a reason not to do it in a similar circumstance.