You might run this thread in a service, and have another thread stop
the service as needed.



Yusuf Saib
Android
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.


On Aug 31, 5:14 am, jsdf <[email protected]> wrote:
> Does anyone out there have thoughts on this?
> Thanks,
> jsdf
>
> On Aug 28, 5:56 pm, jsdf <[email protected]> wrote:
>
>
>
> > Hi Android experts,
> > I have a tricky question that I would like some advice on.
>
> > I have a thread that does a large amount of network and database
> > work.  E.g.:
>
> > new Thread(new Runnable() {
> >   public void run() {
> >     String largeData = getLargeDataFromServer();
> >     Object largeObject = xmlParser.parseFromXml(largeData);
> >     saveLargeObjectToDatabase();
> >     putLargeDataToSecondServer();
> >   }
>
> > }).start();
>
> > The problem I have is that I need to stop this thread at any point.
> > It does not need to stop absolutely immediately, but given limited
> > network and memory on the phone, the sooner I can stop it the better.
>
> > I currently am testing and stopping with a method similar to this:
>
> > new Thread(new Runnable() {
> >   public void run() {
> >     if (shouldStop) return;
> >     String largeData = getLargeDataFromServer();
> >     if (shouldStop) return;
> >     Object largeObject = xmlParser.parseFromXml(largeData);
> >     if (shouldStop) return;
> >     saveLargeObjectToDatabase();
> >     if (shouldStop) return;
> >     putLargeDataToSecondServer();
> >   }
>
> > }).start();
>
> > This makes me very uncomfortable, and litters my code with these
> > shouldStop statements.  Furthermore, if the system is in any of the
> > four long functions, that function has to complete before the test can
> > actually happen.
>
> > I notice that there is a Thread.stop(), but the comments warn against
> > using it.
>
> > Does anyone have suggestions on how to reconfigure the thread so I can
> > stop relatively quickly and regardless of whether execution is in one
> > of its subfunctions?
>
> > Thanks so much in advance,
> > jsdf
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to