Note that there are some explanatory texts on larger screens.

plurals
  1. POBack key is not behaving as usual
    primarykey
    data
    text
    <p>I have an app which has a main activity and a class. When I press the back button, it should close the app, but it does nothing: when I press the button, the button backlight goes on and it goes off. If I press it again, I just hear some sound feedback.</p> <p>My app is constantly doing Bluetooth communication. Can Bluetooth override the normal behavior of the key?</p> <p>I also have onPause and onResume.</p> <p>Tried with onBackPressed, it never gets called:</p> <pre><code> @Override public void onBackPressed() { super.onBackPressed(); Log.i ("INFO","BackKey pressed"); } </code></pre> <p>BtComm class:</p> <pre><code> //Enables Bluetooth if not enabled public void enableBT(){ localAdapter=BluetoothAdapter.getDefaultAdapter(); //If Bluetooth not enable then do it if(localAdapter.isEnabled()==false){ localAdapter.enable(); while(!(localAdapter.isEnabled())){ } } } //connect to both NXTs public boolean connectToNXTs(){ //get the BluetoothDevice of the NXT BluetoothDevice nxt_1 = localAdapter.getRemoteDevice(nxt1); //try to connect to the nxt try { socket_nxt1 = nxt_1.createRfcommSocketToServiceRecord(UUID .fromString("00001101-0000-1000-8000-00805F9B34FB")); socket_nxt1.connect(); success = true; } catch (IOException e) { Log.i("Bluetooth","Err: Device not found or cannot connect"); success=false; } if (success) { Log.i("CONECTE","CONEXION EXITOSA"); } return success; } public void writeMessage(byte[] msg) throws InterruptedException{ //BluetoothSocket connSock; // connSock=socket_nxt1; try { // OutputStreamWriter out =new OutputStreamWriter(connSock.getOutputStream()); // mmOutStream.write(msg); // out.flush(); OutputStream outputStream = socket_nxt1.getOutputStream(); outputStream.write(msg); Log.i("Excelente","COMANDO EXITOSO"); } catch (IOException e) { // TODO Auto-generated catch block Log.i("PROBLEMA","ERROR DE DATOS"); } } public byte [] readMessage(){ byte[] buffer = new byte[64]; Log.i("Excelente","Entre a readmessage"); try { InputStream inputstream = socket_nxt1.getInputStream(); inputstream.read(buffer); //mmInStream.read(buffer); Log.i("Excelente","Lei los datos"); for (int index = 0; index &lt; buffer.length; index++){ Log.i("RECIBIDO:", String.format("0x%20x", buffer[index])); } Log.i("Excelente","Recibi datos y los escribi"); return buffer; } catch (IOException e) { // TODO Auto-generated catch block Log.i("PROBLEMA","ERROR DE DATOS AL RECIBIR"); return null; } } public void cancel() { try { //OutputStream outputStream = socket_nxt1.getOutputStream(); socket_nxt1.close(); } catch (IOException e) { Log.e("ERROR","Unable to close"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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