Jiale Wang
Jiale Wang

Reputation: 181

Does Code in onRequestPermissionsResult / onActivityResult run on UI thread anyway?

Does Code in onRequestPermissionsResult run on UI thread anyway, even if requestPermissions was called on a non-UI thread?

Furthermore, do all callback methods of Activity act like this? Such as onActivityResult?

Upvotes: 1

Views: 442

Answers (1)

TheWanderer
TheWanderer

Reputation: 17844

Callbacks like that run on the UI thread, yes.

If you request permissions asynchronously, Android starts its own internal Activity to deal with that. That essentially nullifies your new Thread, since new components aren't run in the Thread that requested they be created (they're usually run on the main Thread).

Once the permissions request process is done, the internal Activity sets its result, which is sent back to your Activity through the Android framework. Nothing is directly invoked, so the original Thread is ignored.

Upvotes: 1

Related Questions