Reputation: 3318
I want to refresh the activity as i want thatwithout firing any event some work gets performed and activity calls by itself. So, i want to know is there any option in android to refresh the activity by itself.
Upvotes: 4
Views: 11917
Reputation: 54
for other questions I've pulled the most effective ways to do this are:
finish();startActivity(getIntent());
OR
// Refresh main activity upon close of dialog box
Intent refresh =new Intent(this, ActivityWeAreIn.class);
startActivity(refresh);
Note: this also works with Activity objects or from Fragments using getActivity()
Upvotes: -1
Reputation: 7029
You can do this by yourself through a Handler on which you call postDelayed(..)
http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable, long)
Put this in your class:
private final Handler handler = new Handler();
make a function called: doTheAutoRefresh() that does:
private void doTheAutoRefresh() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
doRefreshingStuff(); // this is where you put your refresh code
doTheAutoRefresh();
}
}, 1000);
}
Call this function in your onCreate.
NOTE: this is the basic approach. consider stopping this after onPause has been called and to resume it after onResume. Look at the handler class to see how to remove.
Upvotes: 7
Reputation:
You can create a thread and and call the refresh() with the task you want to refresh
Upvotes: 1