To do this I essentially created a Popup variable like so:
public static class PopupParms { private String burl; private int type; private int position; private Bitmap bm; }
This class is inside the larger class that contains the async task.
PopupParms pp = new PopupParms() and assign values like:
pp.burl = a_url;
pp.position = row_number;
pp.type = row_type;
etc...
Now I call the AsyncTask with:
new buildPopUpWithURL().execute(pp);
The AsyncTask class will look like this:
public class buildPopupWithURL extends AsyncTask '<'PopupParms, Integer, PopupParms'>' { @Override protected void onPreExecute() { } @Override protected PopupParms doInBackground(PopupParms... parms) { HttpGet reuest = new HttpGet(parms[0].burl); . . . Bitmap bm = BitmapFactory.decodeStream(inputstream, null, null); PopupParms pp = new PopupParms(); pp.bm = bm; // broken out for illustration pp.position = parms[0].position; // broken out for illustration pp.type = parms[0].type; // broken out for illustration return pp; } @Override protected void onPostExecute(PopupParms p) { // broken out for illustration PopupParms pms = new PopupParms(); pms.type = p.type; pms.position = p.position; pms.bm = p.bm; // A build method on the main UI buildPopup( pms.position, pms.type, pms.bm); }
In conclusion, I created a custom class variable that contains the multiple fields that need to be passed into an AsyncTask. After I pass that class variable into the AsyncTask, I parse out and read the member fields of that class variable.
High level representation of passing multiple parameters into an AsyncTask:
You can see this live with SpiderOnFire's Widespread Augmented Reality app.
No comments:
Post a Comment