Bluetooth Service

P

Peter123

Fortgeschrittenes Mitglied
8
Also meine App stellt über Bluetooth eine Verbindung zu einem anderen Gerät her. Wenn diese Verbindung erfolgreich war, wird eine neue Activity gestartet.
In der neuen Activity soll mit der Verbindung weitergearbeitet werden.

Das ganze sieht wie folgt aus:

ActivitySuche:
Code:
BluetoothService service = new BluetoothService(this, mHandler);

service.connect(device);



BluetoothService:

Code:
public synchronized void connect(BluetoothDevice device){

try {
        	for (Integer port = 1; port <= 3; port++) {
                
            
			mConnectThread = new ConnectThread(device, port);
			}

 mConnectThread.start();
}
private class ConnectThread extends Thread {

public ConnectThread(BluetoothDevice device, int port){
      mmDevice = device;
      BluetoothSocket tmp = null;
          
       Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
       tmp = (BluetoothSocket) m.invoke(device, 1);
			
				
        mmSocket = tmp;
  }      
public void run() {
     try {
                
                mmSocket.connect();
               
                
            } catch (IOException e) {}
       // Start the connected thread
        connected(mmSocket, mmDevice, mSocketType);
     }
}

private class ConnectedThread extends Thread {
    public ConnectedThread(BluetoothSocket socket, String socketType) {
      
     //Ruft zweite Activity auf
     BluetoothScann.verbunden();

   }
}

Zweite Actitiy:

Code:
 BluetoothService service = new BluetoothService(this, mHandler);


Um diesen Code in der zweiten Activity geht es mir. Habe ich trotz "new BluetoothService" noch zugriff auf die Connection von vorher?

Das ganze lehnt sich stark an das Projekt von google an:
BluetoothChat - Bluetooth Chat | Android Developers

Bei mir gibt es nur halt eine zweite Activity in welcher die Connection noch bestehen muss.
 
Keiner eine Idee dazu?
 

Ähnliche Themen

S
Antworten
4
Aufrufe
4.454
mblaster4711
mblaster4711
N
Antworten
8
Aufrufe
1.018
NerkJ
N
M
Antworten
11
Aufrufe
2.271
jogimuc
J
Zurück
Oben Unten