You can pass the string to the asynctask or doInbackground constructor
new getTrackHistory(mystringvalue).execute();
Then in the constructor
private class getTrackHistory extends AsyncTask<String, Integer, Boolean> { String value; public getTrackHistory(String mystring) { value = mystring; }
Edit:
You can also pass the value to doInbackground()
new TheTask().execute("mystring"); class TheTask extends AsyncTask <String,Void,Void> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); } @Override protected Void doInBackground(String... params) { String value = params[0]; return null; } }
To the question in the comment
new getTrackHistory(mystringvalue,ActivityName.this).execute();
In the constructor
String value; TheInterface listener; public getTrackHistory(String mystring,Context context) { value= mystring; listener = (TheInterface) context; }
Interface
public interface TheInterface { public void theMethod(ArrayList<String> result);
then
In your doInbackground return the result. I assume its ArrayList is of type String. Change arraylist to suit your requirements.
In your onPostExecute
if (listener != null) { listener.theMethod(result); // result is the ArrayList<String> // result returned in doInbackground // result of doInbackground computation is a parameter to onPostExecute }
Implement an interface in your activity class
public class ActivityName implements getTrackHistory.TheInterface
then
@Override public void theMethod(ArrayList<String> result) {
A similar post using the interface
Android Parse JSON stuck on get job .