When we develop the application often use asynchronous processing, are through the inheritance of asynctask implementation, and sometimes with the time-out to do processing, after a period of time regardless of asynchronous execution did not have to do the next thing,
Then I have a simple example here you can look at:
private static final int time_delay = 1500; Private Boolean misloaded; Private Boolean mistimeout; Private Handler Mhandler; Class Inittask extends Asynctask<string, Integer, string> {public inittask () {} @Override Protected string Doinbackground (String ... params) {xxx ();//asynchronous handling of things return null; } @Override protected void OnPostExecute (String result) {Super.onpostexecute (result); Misloaded = true; if (mistimeout) {xxx ();//What happens after asynchronous execution}}} @Override protected void OnCreate (Bund Le Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_start); } @Override public void onbackpressed () {} @Override protected void Onresume () {super.onresume (); misloaded = false; Mistimeout = false; Inittask minittast = new Inittask (); MinittasT.execute (); Mhandler = new Handler (); Mhandler.postdelayed (New Runnable () {@Override public void run () {Mistimeout = True ; if (misloaded) {xxx ();//Timeout Handling Things}}}, Time_delay); }
Hope to help everyone,
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android asynchronous and timeout processing examples