> So if I'm understanding you right I HAVE to interrupt the work that is
> done in the background thread.

If Thread#interrupt() isn't working, then yes. See below...

> That will be difficult, it is not just
> the download of information. I'm setting a geo search at flickr,
> handling the response and so on and so on. Finally giving back some
> links (to photos) which will be downloaded and shown in the GUI of the
> activity.

How long are each one of those operations? If they're each fairly short,
check some flag you set to see if the thread needs to unwind after every
step and abandon the rest of the work at that point.

You may be able to simplify some of this by moving the background thread
into the service and using other means (e.g., broadcasting Intents) to let
the activity know when stuff is ready.

> Isnt't there a possibility to surround the whole "hard work"
> by a try / catch clause (or something similar) which will be invoked
> when I interrupt the thread? And so I could stop the thread nicely.

Its called Thread#interrupt() and you tried that. You can see a trivial
sample code of its use here:

http://www.java2s.com/Code/Java/Threads/Threadsleepandinterrupt.htm

I was under the impression is was not giving you control back. Off the top
of my head, I can think of three possibilities for that, though there may
be more:

1. Dalvik doesn't raise an InterruptedException the way Java does

2. Dalvik does raise an InterruptedException in certain cases (e.g., the
Thread is blocked on wait() or sleep()), but that's not the state the
Thread is in at the time you call interrupt() (e.g., the Thread is in a
true busy loop somewhere in the bowels of the libraries you're using)

3. Dalvik does raise an InterruptedException, but it's getting caught and
eaten before it gets to you, perhaps due to an over-aggressive exception
handler

--
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.1 Published!



--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to