简体   繁体   中英

Starting event handler and class on a new thread in Android

I have two class, one is the main class and other is Bluetooth class.

Bluetooth class has methods for scanning for BLE devices, send data to the Bluetooth devices and event handler if one of the BLE devices sends data.

In the main class, once I determine the number of BLE devices around me, I loop through them and try to get some information. So basically, in the loop I have to wait until I finish communication with the BLE device. Since I'm running this on my main thread, application becomes un-responsive.

I would like to start my Bluetooth class on a different thread. How will I proceed?

Will creating Bluetooth class on a Runnable method, will make my blbuetooth class's event handler to run on a new thread?

Thank you

See the documentation for HandlerThread , Thread and Looper and ThreadPoolExecutor for options. Creating just the Runnable will not start a new thread for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM