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.
Asked
Active
Viewed 1.2k times
4
-
1If you are using BaseAdapter or ArrayAdapter simply call notifyDataSetChanged() to update your view – 100rabh Nov 30 '10 at 06:43
-
@100rabh : right. if he is refreshing a list. he should write, what and how he is actually trying to refresh. than we could give better information. – Patrick Boos Nov 30 '10 at 07:04
-
well i am trying to refresh whole activity – Nikki Nov 30 '10 at 07:06
-
Chk this out: http://stackoverflow.com/questions/6134832/auto-refresh-the-activity/6840666#6840666 – Syed Jul 27 '11 at 07:26
3 Answers
7
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.

Patrick Boos
- 6,789
- 3
- 35
- 36
-
-
well.. then just replace all the autoRefresh() above with doTheAutoRefresh() – Patrick Boos Nov 30 '10 at 07:02
-
I mean to say that is autoRefresh() is predefined or i have to define it – Nikki Nov 30 '10 at 07:04
-
you have to define that function. let me edit above, so it is clear – Patrick Boos Nov 30 '10 at 07:10
-
this code doesn't work. is says add unimplemented functions and want to implement run. – ghostrider Mar 20 '12 at 20:12
-
sorry.. my code was written by hand and i forgot some small part. was more meant as an example than copy paste. but now it should work with copy paste (i hope) :) – Patrick Boos Mar 23 '12 at 01:50
1
You can create a thread and and call the refresh() with the task you want to refresh
-1
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()

Adam Greenberg
- 54
- 2