Bluetooth Discovery Inside A Asynctask
Solution 1:
First of all, java doesn't have functions. It has methods.
Second of all, you shouldn't be using an AsyncTask here. AsyncTasks are used to perform potentially expensive operations off the UI thread. Bluetooth discovery is asynchronous, so you don't need to introduce multiple threads to discover other devices. Further, it looks like all that you are doing in your AsyncTask is defining and registering a new BroadCastReceiver. This will be executed in several milliseconds (creating/executing the actual AsyncTask might even take longer). As a result, your onPostExecute method will be invoked immediately after you register the receiver. This is probably what is confusing you.
Please read through this documentation on Bluetooth in Android... it will step you through the process of setting up your application for Bluetooth discovery.
Post a Comment for "Bluetooth Discovery Inside A Asynctask"