Re: [android-developers] IntentService: Sending Message to a handler on dead thread

2010-09-18 Thread Mark Murphy
On Thu, Sep 16, 2010 at 11:49 AM, Samuh samuh.va...@gmail.com wrote:
 1. What is causing these exceptions?

Probably because of this:

 The IntentService class fires a few AsyncTask from its onHandleIntent() 
 callback.

IntentService already uses a background thread for onHandleIntent().
Hence, do not use AsyncTask -- just execute your code in
onHandleIntent().

 2. How can such exceptions be avoided?

Do not use AsyncTask -- just execute your code in onHandleIntent().

Also, you might consider using a WakefulIntentService, or your own
pattern derived from it, to keep the device awake while you are doing
work:

http://github.com/commonsguy/cwac-wakeful

 3. What happens when the device sleeps?

All processes and threads are suspended.

 4. I've read somewhere that if the network connectivity is through
 WiFi, it is disabled when the device sleeps.

Correct.

 What are the cases that a
 developer should take care of when a device wakes up?

That is impossible to answer in the abstract.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training in Atlanta: http://bignerdranch.com/classes/android

-- 
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


[android-developers] IntentService: Sending Message to a handler on dead thread

2010-09-16 Thread Samuh
We are starting an IntentService periodically using AlarmManager
service. The IntentService class fires a few AsyncTask from its
onHandleIntent() callback.

The setup works well for some time. But when the device is put to
sleep or if the application is exited and resumed after some time,
whenever the IntentService code runs, I get the following exceptions:

Handler{44f1b3a8} sending message to a Handler on a dead thread
java.lang.RuntimeException: Handler{44f1b3a8} sending message to a
Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:181)
at android.os.Handler.sendMessageAtTime(Handler.java:457)
at android.os.Handler.sendMessageDelayed(Handler.java:430)
at android.os.Handler.sendMessage(Handler.java:367)
at android.os.Message.sendToTarget(Message.java:317)
at android.os.AsyncTask$3.done(AsyncTask.java:214)
at java.util.concurrent.FutureTask$Sync.innerSet(FutureTask.java:
252)
at java.util.concurrent.FutureTask.set(FutureTask.java:112)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:
310)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:
1068)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)

When I run the code on the thread that is executing onHandleIntent()
the occurences of this error is minimized. However, I am not sure if
the possibility of it happening is zero.

Questions:

1. What is causing these exceptions?
2. How can such exceptions be avoided?
3. What happens when the device sleeps?
4. I've read somewhere that if the network connectivity is through
WiFi, it is disabled when the device sleeps. What are the cases that a
developer should take care of when a device wakes up?

Please help.

Thanks.

-- 
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