2

Are onTouch(), onClick(), runOnUiThread() running in the same UI thread sequentially? Or do I have to worry about synchronization issues among them?

CJBS
  • 15,147
  • 6
  • 86
  • 135
user256239
  • 17,717
  • 26
  • 77
  • 89

1 Answers1

4

Are onTouch(), onClick(), runOnUiThread() running in the same UI thread sequentially?

Yes. 99.9% of the time, Android will be calling into your methods on the main application thread. The exceptions are:

  • where you are expressly telling it to use a background thread via AsyncTask
  • if you expose an interface via AIDL to third-party apps
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @Wizard: `AsyncTask` is covered many places in the documentation, such as [in its JavaDocs page](https://developer.android.com/reference/android/os/AsyncTask.html). – CommonsWare Mar 17 '17 at 11:26
  • Okay but how can I possibly tell `onTouch()` to use `AsyncTask` or run in worker thread. I'm not telling about the code inside `onTouch` but the method `onTouch` itself. Is it possible to run `onTouch()` itself on a worker thread? – Paresh P. Mar 17 '17 at 11:36
  • @Wizard: "Is it possible to run onTouch() itself on a worker thread?" -- no. My first bullet is referring to `doInBackground()` on `AsyncTask`, where you are called on a background thread. – CommonsWare Mar 17 '17 at 11:50