You can call the cance(boolean) method on the asynctask. And you can pass
true to forcefully remove the thread as per the docs. However it depends on
what the URL and the drawable is doing and if they need to be informed of
cancelling. You can also set a flag to cancel the task and check it often
in the dobackground method if there is a loop of activity going on. In your
case as there is no loop you may want to read up on the URLs and drawables
to see if they have a cancel. then I will try cancel(true) on the asynctask.

Here are some research notes on asynctask if you have patience to read
through:

Understanding Asynctask and ProgressDialogs
http://satyakomatineni.com/item/3536


On Sat, Nov 30, 2013 at 10:58 AM, askl <amal...@gmail.com> wrote:

> *Hi Dear,*
> *Can u please explain how to stop or cancel downloading progress within
> asyntask in android. Here's the my sample code. Please help me to solve
> this problem.*
>
> *private class DownloadPicture extends*
> * AsyncTask<String, Void, Drawable> {*
>
> * @Override*
> * protected Drawable doInBackground(String... urls) {*
>
> * try {*
> * InputStream nextPicIs = (InputStream) new URL(urls[0])*
> * .getContent();*
> * Drawable nextPicDraw = Drawable.createFromStream(nextPicIs,*
> * "Jathaka Katha");*
>
> * nextPicIs.close();*
>
> * return nextPicDraw;*
>
> * } catch (Exception e) {*
> * System.out.println("IMAGE EXCEPTION " + e);*
> * return null;*
> * }*
> * }*
>
> * @Override*
> * protected void onPostExecute(Drawable result) {*
>
> * if (result != null) {*
> * Bitmap currentImg= ((BitmapDrawable) result).getBitmap();*
>
> *                                img_view.setImageBitmap(currentKatha);*
>
> * } else {*
> *
> img_view.setBackgroundResource(R.drawable.play_default);*
> * }*
>
> * onCancelled();*
> * }*
>
> * @Override*
> * protected void onCancelled() {*
> * super.onCancelled();*
> * }*
> * }*
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
http://satyakomatineni.com/android/training
http://satyakomatineni.com
http://androidbook.com
http://twitter.com/SatyaKomatineni

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to