Do callbacks occur on the main (UI) thread?

One case where Android will call your code on some other thread will be if you create a remote service, exposed via AIDL -- those AIDL methods will be called on a binder thread, not the main application thread.

However, that is the exception. As the others have noted, the vast majority of these are called on the main application thread.


When in doubt you can use Log.i("TAG", Thread.currentThread().getName()); and see :)


In my experience, those callbacks always come back on a non-UI thread. Have you tried Activity.runOnUiThread() to make sure your code runs on the UI thread? You would still take the performance hit because it takes longer for this code to run, but you would avoid some of the more common problems with thread synchronization.

Tags:

Android