• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Help - quiting Thread, slow phone

rhast

Lurker
Jul 26, 2013
2
0
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):

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) { }
    }
}
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.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones