Skip to content Skip to sidebar Skip to footer

Where Do I Extend The Asynctask?

I have a login system consisting of the following elements: LoginActivity uses LoginController uses RestClient to call a web service with Execute(). I want the call to the web serv

Solution 1:

AsyncTask has a few methods that will help you with this.

Extend the AsyncTask:

publicclassMyTaskextendsAsyncTask<Object, Void, Void>

  @OverrideprotectedvoidonPreExecute() {
    // show progress dialog
  }

  @OverrrideprotectedVoiddoInBackground(Object... params) {
    HttpUriRequest req = (HttpUriRequest) params[0];
    String myString = (String) params[1];

    // connectreturnnull;
  }

  @OverrideprotectedvoidonPostExecute(Void result) {
    // hide dialog
  }
}

To execute this with parameters, try this:

myTask.execute(request, "aString");

Where request is an object of type HttpUriRequest. Remember the order of the parameters matter.

If you want to update the status while the service is connecting you can use this method as Rasel said:

onProgressUpdate() {
  // Update view in progress dialog
}

Post a Comment for "Where Do I Extend The Asynctask?"