I try to use a progress dialo开发者_如何转开发g. My code:
//Method to load data wire BT
private void dataload() {
if(D) Log.e(TAG, "++ Data Load Function ++");
// make discoverable
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
//Show Progress Dialog
ProgressDialog dialog = ProgressDialog.show(BluetoothServer.this, "", "Loading, Please wait...", true);
//Establish server connection
mAcceptThread = new AcceptThread();
mAcceptThread.run();
//End progress dialog
dialog.dismiss();
//mAcceptThread.cancel();
}
Thats inside the main activity, and AcceptThread is in the same class, but extends Thread as a new class. The problem is, that no progress bar shows up.
Where is the problem, do I have to put the AcceptThread in another Activity?
Another problem is, that I get an ANR if the AcceptThread is called. I should be a problem, that it´s not running in the background, but why?
Hope you can help.
To start a thread, call the start()
method, not run()
, since run()
will invoke the method on the current thread, while start()
will create a new thread and invoke the run method in it. But looking at your code, seems like you need to use AsyncTask.
精彩评论