Hello.
I'm new to android programming and this is my first project and would be very grateful if someone would take his time and help me out.
I've been making a bluetooth application which I have been testing on my phone (since I can't use emulator with bluetooth).
Everything works fine until I make a new AcceptThread and start it. (the code is from android bluetooth tutorial):
When I run an app for the first time everything seems to work fine. But when I try to
rerun it with eclipse the phone freezes or it gets very slow and I have to restart the phone.
I've tried to:
- uninstall the app after the first run, but during uninstall process the phone gets slow and it stays slow until reset.
- force close the app with task manager (it does kill it, but the phone is slow again).
- use the cancel() from AcceptThread in onDestroy(), same result.
I don't have any log, since the problem appears before the application reruns.
I'm new to android programming and this is my first project and would be very grateful if someone would take his time and help me out.
I've been making a bluetooth application which I have been testing on my phone (since I can't use emulator with bluetooth).
Everything works fine until I make a new AcceptThread and start it. (the code is from android bluetooth tutorial):
Code:
private class AcceptThread extends Thread {
private final BluetoothServerSocket mmServerSocket;
public AcceptThread() {
// Use a temporary object that is later assigned to mmServerSocket,
// because mmServerSocket is final
BluetoothServerSocket tmp = null;
try {
// MY_UUID is the app's UUID string, also used by the client code
tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
} catch (IOException e) { }
mmServerSocket = tmp;
}
public void run() {
BluetoothSocket socket = null;
// Keep listening until exception occurs or a socket is returned
while (true) {
try {
socket = mmServerSocket.accept();
} catch (IOException e) {
break;
}
// If a connection was accepted
if (socket != null) {
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(socket);
mmServerSocket.close();
break;
}
}
}
/** Will cancel the listening socket, and cause the thread to finish */
public void cancel() {
try {
mmServerSocket.close();
} catch (IOException e) { }
}
}
rerun it with eclipse the phone freezes or it gets very slow and I have to restart the phone.
I've tried to:
- uninstall the app after the first run, but during uninstall process the phone gets slow and it stays slow until reset.
- force close the app with task manager (it does kill it, but the phone is slow again).
- use the cancel() from AcceptThread in onDestroy(), same result.
I don't have any log, since the problem appears before the application reruns.