Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing two parametes to asynctask method. how to?
    primarykey
    data
    text
    <p>I'm designing an application that frequently communicates to a web server for updates. Communication happens only when user requests. I found AsyncTask could be helpful here. So I modified one class to serve my application as AsyncTask.</p> <p>I want to pass an url and http post parameters to anysc class's doInBackground process. I can't figure out how to do it.</p> <p>Here's it- </p> <pre><code>public class GetXMLFromServer extends AsyncTask&lt; String, Void, String&gt; { private Context context; GetXMLCallback gc = null; ProgressDialog progressDialog; public GetXMLFromServer(Context context, GetXMLCallback gc) { this.context = context; this.gc = gc; progressDialog = new ProgressDialog(this.context); } protected void onPreExecute() { progressDialog.setMessage("Fetching..."); progressDialog.show(); } @Override protected void onPostExecute(String result) { gc.onSuccess(result); progressDialog.dismiss(); } @Override protected String doInBackground(String... params) { String response = ""; response=CustomHttpClient.executeHttpPost(params[0]); return null; } //Confused how to pass URL and http post parameters to doInBackground(). } </code></pre> <p>I've one interface that is used to process response sent from onPostExecute(). It is as fallows.</p> <pre><code> package com.project.main.external; public interface GetXMLCallback { void onSuccess(String downloadedString); void onFailure(Exception exception); } </code></pre> <p>And here is my main activity that calls for http response --</p> <pre><code> public class UpdateList extends Activity implements GetXMLCallback { //above line also throws error that interface methods are not implemented yet //they are (few lines below) defined. private TextView textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_layout); textView = (TextView) findViewById(R.id.TextView01); } GetXMLCallback gc = new GetXMLCallback() { public void onFailure(Exception exception) { } public void onSuccess(String downloadedString) { textView.setText(downloadedString); } }; public void getUpdates(View view) { GetXMLFromServer task = new GetXMLFromServer(UpdateList.this, gc); task.execute(WebConstants.GET_UPDATES); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload