1. Download our Official Android App: Forums for Android!

Apps Help - quiting Thread, slow phone

Discussion in 'Android Development' started by rhast, Jul 26, 2013.

  1. rhast

    rhast Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jul 26, 2013

    Jul 26, 2013
    2
    0
    5
    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 (Text):
    1. private class AcceptThread extends Thread {
    2.     private final BluetoothServerSocket mmServerSocket;
    3.  
    4.     public AcceptThread() {
    5.         // Use a temporary object that is later assigned to mmServerSocket,
    6.         // because mmServerSocket is final
    7.         BluetoothServerSocket tmp = null;
    8.         try {
    9.             // MY_UUID is the app's UUID string, also used by the client code
    10.             tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
    11.         } catch (IOException e) { }
    12.         mmServerSocket = tmp;
    13.     }
    14.  
    15.     public void run() {
    16.         BluetoothSocket socket = null;
    17.         // Keep listening until exception occurs or a socket is returned
    18.         while (true) {
    19.             try {
    20.                 socket = mmServerSocket.accept();
    21.             } catch (IOException e) {
    22.                 break;
    23.             }
    24.             // If a connection was accepted
    25.             if (socket != null) {
    26.                 // Do work to manage the connection (in a separate thread)
    27.                 manageConnectedSocket(socket);
    28.                 mmServerSocket.close();
    29.                 break;
    30.             }
    31.         }
    32.     }
    33.  
    34.     /** Will cancel the listening socket, and cause the thread to finish */
    35.     public void cancel() {
    36.         try {
    37.             mmServerSocket.close();
    38.         } catch (IOException e) { }
    39.     }
    40. }
    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.
     

    Advertisement

  2. rhast

    rhast Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jul 26, 2013

    Jul 26, 2013
    2
    0
    5

Share This Page

Loading...