Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep bluetooth activity active
    primarykey
    data
    text
    <p>In my application, I am using <a href="http://bazaar.launchpad.net/~janos-gyerik/bluetoothviewer/main/files" rel="nofollow">Janos Gyerik's BluetoothViewer</a> code to connect via Bluetooth. </p> <p>I also have a <code>TCPServer</code> Class to connect via USB. </p> <pre><code>public void connectViaUSB() { if (GlobalVariables.connectionstatus == 0) { mTCPServer = new TCPServer(2222, getCurrentActivity()); mTCPServer.start(); mTCPServer.setResponseReceivedListener(this); } </code></pre> <p>The problem is, <code>BluetoothViewer</code> is written as an <code>Activity</code>. One needs to start the activity to connect, but when I switch to another activity connection is lost. </p> <p>I need to either keep that activity up all the time, or find a way to modify it. How can I fix this situation?</p> <p><strong>EDIT</strong> </p> <p>`<br> public class MyService extends Service {</p> <pre><code>private static final String TAG = "MyService"; @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); Log.d(TAG, "onCreate"); BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter(); mAdapter.enable(); BluetoothChatService mChatService = new BluetoothChatService(mHandler); BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:12:11:13:19:26"); mChatService.connect(device); } @Override public void onDestroy() { Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show(); //stop thread } @Override public void onStart(Intent intent, int startid) { Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show(); Log.d(TAG, "onStart"); //start thread (again) } </code></pre> <p>}` </p> <p>How can I make the Bluetooth connection from this Service Class? It requires me to move mHandler and I did. Now I'm getting RuntimeException: Unable to create .MyService: NullPointerException</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload