Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Primary issue :</strong></p> <pre><code>SetConstant.CONTENT_ID = contentId[i]; String URL = SetConstant.URL_DOWNLOAD_CONTENT+contentId[i]; </code></pre> <p>Here, you are facing trouble. As @Sofi Software LLC's answer, you are using a global variable, whose value is being changed by the main thread, in another thread.</p> <p><strong>Secondary Issue :</strong></p> <ul> <li>If you want a progress bar to update, you have to update its value;<br> it doesn't update itself.</li> </ul> <p>You do need to download the image in AsyncTask (Downloading from URL). Effectively to achieve your functionality, you need to do</p> <ul> <li>Create AsyncTask to download your image (implement download in doInBackground()), also have a boolean (say isImageDownloaded) to track if the image is successfully downloaded in postExecute().</li> <li>Don't forget to also show your progress bar before initiating the download</li> <li>Execute your AsyncTask to initiate download</li> <li>Create extension of android.os.CountDownTimer to countdown a minimum time</li> <li>On the method onFinish() check the boolean that you track, if it is false then you cancel the AsyncTask and throw the toast/dialog that you intended</li> <li>Running multipule instance of AsyncTask is not a good idea, so do one after another. You can execute your AsyncTask's on an Executor using executeOnExecutor().To make sure that the threads are running in a serial fashion please use: SERIAL_EXECUTOR.</li> </ul> <p><strong>Following resources may help you #</strong></p> <p>If you need to download an image, show progress bar and load in a imageview</p> <ul> <li><a href="https://github.com/koush/UrlImageViewHelper" rel="nofollow noreferrer">https://github.com/koush/UrlImageViewHelper</a></li> <li><a href="http://developer.aiwgame.com/imageview-show-image-from-url-on-android-4-0.html" rel="nofollow noreferrer">http://developer.aiwgame.com/imageview-show-image-from-url-on-android-4-0.html</a></li> <li><a href="http://blog.blundell-apps.com/imageview-with-loading-spinner/" rel="nofollow noreferrer">http://blog.blundell-apps.com/imageview-with-loading-spinner/</a></li> </ul> <p>If you need to download multiple files (here, for images) using AsyncTask</p> <ul> <li><a href="https://stackoverflow.com/questions/5079335/problem-with-downloading-multiple-files-using-asynctask">Problem with downloading multiple files using AsyncTask</a></li> <li><a href="https://stackoverflow.com/questions/5103727/how-to-get-back-the-task-completion-status-in-asynctask">How to get back the task completion status in AsyncTask</a></li> <li><a href="https://stackoverflow.com/questions/5041978/implement-progress-bar-for-file-download-in-android">Implement Progress Bar for File Download in Android</a></li> </ul> <p><strong>EDIT:</strong></p> <p>From <a href="http://developer.aiwgame.com/imageview-show-image-from-url-on-android-4-0.html" rel="nofollow noreferrer">http://developer.aiwgame.com/imageview-show-image-from-url-on-android-4-0.html</a></p> <pre><code>new DownloadImageTask((ImageView) findViewById(R.id.imageView1)) .execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png"); } public void onClick(View v) { startActivity(new Intent(this, IndexActivity.class)); finish(); } private class DownloadImageTask extends AsyncTask&lt;String, Void, Bitmap&gt; { ImageView bmImage; public DownloadImageTask(ImageView bmImage) { this.bmImage = bmImage; } protected Bitmap doInBackground(String... urls) { String urldisplay = urls[0]; Bitmap mIcon11 = null; try { InputStream in = new java.net.URL(urldisplay).openStream(); mIcon11 = BitmapFactory.decodeStream(in); } catch (Exception e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return mIcon11; } protected void onPostExecute(Bitmap result) { bmImage.setImageBitmap(result); } } </code></pre> <p>From <a href="https://stackoverflow.com/questions/7125490/image-download-in-an-android-imageview-and-progressbar-implementation">Image download in an Android ImageView and Progressbar implementation</a></p> <pre><code> // note that you could also use other timer related class in Android aside from this CountDownTimer, I prefer this class because I could do something on every interval basis // tick every 10 secs (or what you think is necessary) CountDownTimer timer = new CountDownTimer(30000, 10000) { @Override public void onFinish() { // check the boolean, if it is false, throw toast/dialog } @Override public void onTick(long millisUntilFinished) { // you could alternatively update anything you want every tick of the interval that you specified } }; timer.start() </code></pre>
 

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