Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to force quit a Thread
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kamran Shamim  
View profile  
 More options May 1 2012, 4:12 am
From: Kamran Shamim <krsha...@gmail.com>
Date: Tue, 1 May 2012 01:12:19 -0700 (PDT)
Local: Tues, May 1 2012 4:12 am
Subject: Re: [android-developers] How to force quit a Thread

Quite right, Kristopher. I think that it all depends on what Matt would
like to do.
I think that the AsyncTask would do what he wants, but added functionality
(and therefore perhaps complexity) could be available by using an
IntentService, which is a service that automatically runs a worker thread
as well (pretty simple to implement). I like this as I can bind from
different activities, if I have to, and if the killing of the thread causes
problems (which should not happen with the AsyncTask), then at least I can
"divorce" the service (and therefore the thread) from the activity and UI
thread, and let the service deal with stopping the thread (which will
probably cascade from unbinding the service).
 I am not sure of the risk of delayed garbage collection, but I would tend
to trust the DVM to deal with this gracefully and punctually - worth an
implementation and then testing if we want room for added functionality
compared to a service-less thread.

Kamran

On Monday, April 30, 2012 9:34:57 PM UTC+2, Kristopher Micinski wrote:

> Except that a service runs in the main application thread by default,
> so even if you're running it in a service you'll still need a thread
> and some way to communicate with it.

> yes, using an AsyncTask would be an alternative, and what is typically
> done in these situations where you're waiting for data to load.

> Kris

> On Mon, Apr 30, 2012 at 3:29 AM, Kamran Shamim <krsha...@gmail.com>
> wrote:
> > Thank you , Kristopher. That is an interesting read. This is an
> interesting
> > discussion as it addresses a (probably) common situation.
> > My penny's worth: Would it not be better to run the connection through a
> > service, rather than a thread? I have a feeling that this would be
> easier to
> > manage in the case described.
> > An alternative would be to use an AsyncTask and use cancel(booelan) to
> stop
> > it, and isCancelled() in the task (and therefore the thread essentially
> > watches itself to speed up the kill).

> > On Monday, 30 April 2012 06:47:03 UTC+2, Kristopher Micinski wrote:

> >> read this:

> http://docs.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDe...

> >> On Mon, Apr 30, 2012 at 12:33 AM, Matt Clark <mrclark32...@gmail.com>
> >> wrote:
> >> > What do you mean use flags?
> >> > The app hangs on lines that wait for an HTTP response, so i want to
> be
> >> > able
> >> > to just cut them off mid execution if I have to, i cant call check
> >> > statements before and after.
> >> > Sorry, I do not know a whole lot about Threading.

> >> > On Monday, April 30, 2012 12:09:25 AM UTC-4, Ankita wrote:

> >> >> stop(),destroy() etc. methods were deprecated by JDK versions, so
> must
> >> >> have not got support now. To stop thread, you should try to use
> flags,
> >> >> AFAIK.

> >> >> On Mon, Apr 30, 2012 at 9:34 AM, Matt Clark <mrclark32...@gmail.com>

> >> >> wrote:

> >> >>> I am creating an app that sends various HTTP requests in seperate
> >> >>> threads, while doing so brings up a loading screen. If the network
> >> >>> request
> >> >>> is taking longer then the user expects, I want them to be able to
> >> >>> press the
> >> >>> back button to force quit the thread, and dismiss the loading
> screen.
> >> >>> I have my thread set up as:

> >> >>> dataThread = new Thread(new Runnable() {
> >> >>> public void run() {
> >> >>> //...
> >> >>> //Networking Data and Handlers
> >> >>> //...
> >> >>> }
> >> >>> });
> >> >>> dataThread.start();

> >> >>> and where I want to force quit at onBackPressed() I have tried:

> >> >>> dataThread.stop();
> >> >>> dataThread.destroy();
> >> >>> dataThread.interrupt();

> >> >>> And none of them work, Android does not support stop(), or
> destroy(),
> >> >>> and
> >> >>> interrupt() does nothing to stop the thread. I do not care about
> >> >>> exceptions
> >> >>> as everything will be caught, I just want it to allow the user to
> >> >>> resume
> >> >>> doing what they want, if it hangs on requests, or even retry the
> >> >>> request..

> >> >>> Any and all help is greatly appreciated.
> >> >>> ~Matt

> >> >>> --
> >> >>> 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+unsubscribe@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 post to this group, send email to
> android-developers@googlegroups.com
> >> > To unsubscribe from this group, send email to
> >> > android-developers+unsubscribe@googlegroups.com
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/android-developers?hl=en

> > On Monday, 30 April 2012 06:47:03 UTC+2, Kristopher Micinski wrote:

> >> read this:

> http://docs.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDe...

> >> On Mon, Apr 30, 2012 at 12:33 AM, Matt Clark <mrclark32...@gmail.com>
> >> wrote:
> >> > What do you mean use flags?
> >> > The app hangs on lines that wait for an HTTP response, so i want to
> be
> >> > able
> >> > to just cut them off mid execution if I have to, i cant call check
> >> > statements before and after.
> >> > Sorry, I do not know a whole lot about Threading.

> >> > On Monday, April 30, 2012 12:09:25 AM UTC-4, Ankita wrote:

> >> >> stop(),destroy() etc. methods were deprecated by JDK versions, so
> must
> >> >> have not got support now. To stop thread, you should try to use
> flags,
> >> >> AFAIK.

> >> >> On Mon, Apr 30, 2012 at 9:34 AM, Matt Clark <mrclark32...@gmail.com>

> >> >> wrote:

> >> >>> I am creating an app that sends various HTTP requests in seperate
> >> >>> threads, while doing so brings up a loading screen. If the network
> >> >>> request
> >> >>> is taking longer then the user expects, I want them to be able to
> >> >>> press the
> >> >>> back button to force quit the thread, and dismiss the loading
> screen.
> >> >>> I have my thread set up as:

> >> >>> dataThread = new Thread(new Runnable() {
> >> >>> public void run() {
> >> >>> //...
> >> >>> //Networking Data and Handlers
> >> >>> //...
> >> >>> }
> >> >>> });
> >> >>> dataThread.start();

> >> >>> and where I want to force quit at onBackPressed() I have tried:

> >> >>> dataThread.stop();
> >> >>> dataThread.destroy();
> >> >>> dataThread.interrupt();

> >> >>> And none of them work, Android does not support stop(), or
> destroy(),
> >> >>> and
> >> >>> interrupt() does nothing to stop the thread. I do not care about
> >> >>> exceptions
> >> >>> as everything will be caught, I just want it to allow the user to
> >> >>> resume
> >> >>> doing what they want, if it hangs on requests, or even retry the
> >> >>> request..

> >> >>> Any and all help is greatly appreciated.
> >> >>> ~Matt

> >> >>> --
> >> >>> 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+unsubscribe@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 post to this group, send email to
> android-developers@googlegroups.com
> >> > To unsubscribe from this group, send email to
> >> > android-developers+unsubscribe@googlegroups.com
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/android-developers?hl=en

> > On Monday, 30 April 2012 06:47:03 UTC+2, Kristopher Micinski wrote:

> >> read this:

> http://docs.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDe...

> >> On Mon, Apr 30, 2012 at 12:33 AM, Matt Clark <mrclark32...@gmail.com>
> >> wrote:
> >> > What do you mean use flags?
> >> > The app hangs on lines that wait for an HTTP response, so i want to
> be
> >> > able
> >> > to just cut them off mid execution if I have to, i cant call check
> >> > statements before and after.
> >> > Sorry, I do not know a whole lot about Threading.

> >> > On Monday, April 30, 2012 12:09:25 AM UTC-4, Ankita wrote:

> >> >> stop(),destroy() etc. methods were deprecated by JDK versions, so
> must
> >> >> have not got support now. To stop thread, you should try to use
> flags,
> >> >> AFAIK.

> >> >> On Mon, Apr 30, 2012 at 9:34 AM, Matt Clark <mrclark32...@gmail.com>

> >> >> wrote:

> >> >>> I am creating an app that sends various HTTP requests in seperate
> >> >>> threads, while doing so brings up a loading screen. If the network
> >> >>> request
> >> >>> is taking longer then the user expects, I want them to be able to
> >> >>> press the
> >> >>> back button to force quit the thread, and dismiss the loading
> screen.
> >> >>> I have my thread set up as:

> >> >>> dataThread = new Thread(new Runnable() {
> >> >>> public void run() {
> >> >>> //...
> >> >>> //Networking Data and Handlers
> >> >>> //...
> >> >>> }
> >> >>> });
> >> >>> dataThread.start();

> >> >>> and where I want to force quit at onBackPressed() I have tried:

> >> >>> dataThread.stop();
> >> >>> dataThread.destroy();
> >> >>> dataThread.interrupt();

> >> >>> And none of them work, Android does not support stop(), or
> destroy(),
> >> >>> and
> >> >>> interrupt() does nothing to stop the thread. I do not care about
> >> >>> exceptions
> >> >>> as everything will be caught, I just want it to allow the user to
> >> >>> resume
> >> >>> doing what they want, if it hangs on requests, or even retry the
> >> >>> request..

> >> >>> Any and all help is greatly appreciated.
> >> >>> ~Matt

> >> >>> --
> >> >>> 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+unsubscribe@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 post to this group, send email to
> android-developers@googlegroups.com
> >> > To unsubscribe from this group, send email to
> >> > android-developers+unsubscribe@googlegroups.com
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/android-developers?hl=en

> > On Monday, 30 April 2012 06:47:03 UTC+2, Kristopher Micinski wrote:

> >> read this:

> http://docs.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDe...

> >> On Mon, Apr 30, 2012 at 12:33 AM, Matt Clark <mrclark32...@gmail.com>
> >> wrote:
> >> > What do you mean use flags?
> >> > The app hangs on lines that wait for an HTTP response, so i want to
> be
> >> > able
> >> > to just cut them off mid execution if I have to, i cant call check
> >> > statements before and after.
> >> > Sorry, I do not know a whole lot about Threading.

> >> > On Monday, April 30, 2012 12:09:25 AM UTC-4, Ankita wrote:

> >> >> stop(),destroy() etc. methods were deprecated by JDK versions, so
> must
> >> >> have not got support now. To stop thread, you should try to use
> flags,
> >> >> AFAIK.

> >> >> On Mon, Apr 30, 2012 at 9:34 AM, Matt Clark <mrclark32...@gmail.com>

> >> >> wrote:

> >> >>> I am creating an app that sends various HTTP requests in seperate
> >> >>> threads, while doing so brings up a loading screen. If the network
> >> >>> request
> >> >>> is taking longer then the user expects, I want them to be able to
> >> >>> press the
> >> >>> back button to force quit the thread, and dismiss the loading
> screen.
> >> >>> I have my thread set up as:

> >> >>> dataThread = new Thread(new Runnable() {
> >> >>> public void run() {
> >> >>> //...
> >> >>> //Networking Data and Handlers
> >> >>> //...
> >> >>> }
> >> >>> });
> >> >>> dataThread.start();

> >> >>> and where I want to force quit at onBackPressed() I have tried:

> >> >>> dataThread.stop();
> >> >>> dataThread.destroy();
> >> >>> dataThread.interrupt();

> >> >>> And none of them work, Android does not support stop(), or
> destroy(),
> >> >>> and
> >> >>> interrupt() does nothing to stop the thread. I do not care about
> >> >>> exceptions
> >> >>> as everything will be caught, I just want it to allow the user to
> >> >>> resume
> >> >>> doing what they want, if it hangs on requests, or even retry the
> >> >>> request..

> >> >>> Any and all help is greatly appreciated.
> >> >>> ~Matt

> >> >>> --
> >> >>> 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+unsubscribe@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 post to this group, send email to
> android-developers@googlegroups.com
> >> > To unsubscribe from this group, send email to
> >> > android-developers+unsubscribe@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 post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/android-developers?hl=en


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.