In my app, I use a shared HandlerThread like this:
public static synchronized HandlerThread getSharedPriorityThread(){
if(sharedPrioThread == null){
sharedPrioThread = new HandlerThread("sharedPrioThread",
android.os.Process.THREAD_PRIORITY_DISPLAY){
@Override
public boolean quit() {
throw new NullPointerException("tried to quit sharedPrioThread looper!");
}
};
sharedPrioThread.setDaemon(true);
sharedPrioThread.start();
}
if(sharedPrioThread == null){
throw new NullPointerException("sharedPrioThread is null!");
}
if(sharedPrioThread.getLooper() == null){
throw new NullPointerException("sharedPrioThread looper is null");
}
return sharedPrioThread;
}
quit() is overriden in order to intercept any hidden calls to quit() on the
looper.
In addition, ACRA is configured to intercept all Exceptions and send them
to a GoogleDocs spreadsheet, so I am sure I would not miss any.
>From time to time (when the app has run for some time), I get this reported
by ACRA on a real device (no exceptions before this one):
"java.lang.RuntimeException: Unable to start activity ...
Caused by: java.lang.NullPointerException: sharedWorkerThread looper is null
at com.myapp.Utils.getSharedWorkerThread(Utils.java:112)
...
at
android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
at android.app.Activity.performStart(Activity.java:3791)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
... 11 more
How can this happen (i.e. getLooper() suddenly returns null withouth quit()
being called on the looper before)?
As far as I understand this, the looper must have been exited as the
threads isAlive() method returns false. Should this be possible at all in a
looper?
I am using this HandlerThread for multiple Handlers (which might be
nullified from time to time) as well as its looper for a locationListener.
Is this a problem? Is it a problem because it is a daemon thread?
Thanks!
--
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