How can I update activity?

I want to update the activity, because I want that in the absence of any event, some work is performed, and the actions are called by themselves. So, I want to know if there is any option in android to update the action myself.

+4
source share
3 answers

You can do it yourself through the 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(); 

create a function: doTheAutoRefresh (), which 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 the onCreate file.

NOTE: this is a basic approach. think about stopping it after onPause has been called and resuming it after onResume. See the handler class to see how to remove it.

+5
source

You can create a thread and call refresh () with the task you want to update

+1
source

on other issues, I pulled out the most effective ways to do this:

 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 fragments using getActivity ()

-1
source

All Articles