14 thoughts on “Android – Proper way to cancel AsyncTask

  1. androidexperts

    u can check network connection by

    private boolean checkInternetConnection() {

    ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (conMgr.getActiveNetworkInfo() != null
    && conMgr.getActiveNetworkInfo().isAvailable()
    && conMgr.getActiveNetworkInfo().isConnected()) {

    tryLogin();
    return true;

    } else {
    Toast.makeText(Login.this, “Internet Connection Not Present”, Toast.LENGTH_LONG).show();
    Log.v(TAG, “Internet Connection Not Present”);
    return false;
    }
    }

    Reply
    1. Vikas Post author

      This work well on device. But do some other testing. Try to disable network adapter of pc, then check it in emulator. This method will not work as it is still connected to 10.0.2.2 i.e. pc’s localhost!

      Reply
  2. androidexperts

    hi, I m not getting why u want to disable LAN connection,any way as per my knowledge, check ur logcat ,if you are getting exception of “java.net.UnknownHostException: http://www.urweb.com“, and you can handle this by try{ urLoginProcess….. }catch (IOException e) {e.printtrace();}
    and one more tips if u use my “checkInternetConnection()” in thread then it be faster as like

    showDialog(0);
    t = new Thread() {
    @Override
    public void run() {
    Looper.prepare();
    checkInternetConnection();
    removeDialog(0);
    }
    };
    t.start();

    and one more thing ur link “here” is not working plz check it, i ll try if i can give you better solution

    Reply
      1. androidexperts

        OK, Its working, but sry I can’t help you more on regarding current topic, bcz as per my above suggestion i ve tried with above my code and it working perfect(not FC) even if LAN is disable… any way all D best

  3. Pingback: Cancel asynctask download on backbutton press : Android Community - For Application Development

  4. Pingback: Json can not be convert to int : Android Community - For Application Development

  5. Pingback: When I developing an Android application ,how can I cancel a running AsyncTask? : Android Community - For Application Development

  6. sonu

    hi..i am new to android development, i m using mysql as backend.servlet(webservice) to communicate with database.i tried your login code.u have mentioned some code like as parameter to WebServiceURL,””/cfc/iphonewebservice.cfc?returnformat=json&method=validateUserLogin&username=”.
    what is it actually??webservice page URL after running on browser??

    Reply
  7. Frank

    ” if (isCancelled()) {
    publishProgress(CANCELLED);
    return (null); // don’t forget to terminate this method
    }”
    in this statement the publishProgress(CANCELLED) is never called when the task is cancelled. But it does call the @Override onCancelled() method for the async task.
    Can you explain if this is true.

    Reply
  8. www.pinterest.com

    Plus size women can now get maternity clothes for childbirth and later for nursing the baby as well as brassieres and nighties they can put on after the baby has been born. You take in right, obtain a good amount
    of exercise together with ensure you attend to the actual skin.
    Consumers are savvy and will shop around for
    the best deals; with the advent of the internet shoppers now realize that high
    street stores are no longer the best places to find a bargain.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s