Android asynchronous and timeout processing examples

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.