Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing parameters into AsyncTask
    primarykey
    data
    text
    <p>Hi so i'm trying to grab a image from a url link via AsyncTask, the function to grab the image itself work fine. but what i trying to do is to pass the src variable into a asyncTask which seems to be not working for me. the return will be blank.</p> <p>here is the code:</p> <pre><code> private AsyncTask&lt;String, Void, Drawable&gt; task2; Drawable profile; public Drawable getProfile(String src){ task2 = new AsyncTask&lt;String, Void, Drawable&gt;() { ProgressDialog dialog2; InputStream is; Drawable d; @Override protected void onPreExecute(){ dialog2 = new ProgressDialog(Thoughts.this, ProgressDialog.STYLE_SPINNER); dialog2.setMessage("Loading Data..."); dialog2.setCancelable(false); dialog2.setCanceledOnTouchOutside(false); dialog2.show(); } @Override protected Drawable doInBackground(String... src) { try { is = (InputStream) new URL(src[0]).getContent(); d = Drawable.createFromStream(is, "src name"); return d; }catch (Exception e) { e.toString(); return null; } } @Override protected void onPostExecute(Drawable result2) { profile = result2; dialog2.dismiss(); } }; task2.execute(src); return profile; } </code></pre> <p>and i call it like this at the onCreate();</p> <pre><code>Drawable p4 = getProfile("http://..../xyz.jpg"); Drawable p5 = getProfile("http://..../xyz.jpg"); ImageView thoughtsProfilePic =(ImageView) findViewById(R.id.ivProfilePicData); ImageView thoughtsProfilePic1 =(ImageView) findViewById(R.id.ivProfilePicData1); thoughtsProfilePic.setImageDrawable(p4); thoughtsProfilePic1.setImageDrawable(p5); </code></pre>
    singulars
    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.
    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