android studio应用程序调用多个命令后崩溃



我想构建一个应用程序来控制我的arduino汽车。在调用多个命令来控制我的汽车后,蓝牙断开连接,我收到错误:E/Error: in forward:Broken pipe。这是什么意思?在应用程序断开连接后,汽车保持在我按下的最后一个命令上。

在这个Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()之后,汽车不接受任何命令。

CarControl类:

String address = null;
private ProgressDialog progress;
BluetoothAdapter myBt = null;
BluetoothSocket btSocket = null;
private boolean isBtConnected = false;
private void resetConn()
{
myBt = null;
btSocket = null;
isBtConnected = false;
new connectbt().execute();
}
@Override
protected void onStop() {
super.onStop();
disconnect();
}
static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bot);
//  Toolbar toolbar = findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);
f1=  findViewById(R.id.up1);
l1= findViewById(R.id.left1);
r1= findViewById(R.id.right1);
b1= findViewById(R.id.back1);
st1= findViewById(R.id.stop1);
linef=findViewById(R.id.linef1);
auto_button = findViewById(R.id.button_auto);
Intent newint = getIntent();
address = newint.getStringExtra(MainActivity.EXTRAADD);
new  connectbt().execute();


private void disconnect()
{
if (btSocket!=null)
{
try
{
btSocket.close(); //close connection
}
catch (IOException e)
{
msg("Error");
Log.e("Error", e.getMessage());
resetConn();
}
}
finish(); //return to the first layout
}
// fast way to call Toast
private void msg(String s)
{
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
}
private class connectbt extends AsyncTask<Void, Void, Void>  // UI thread
{
private boolean ConnectSuccess = true; //if it's here, it's almost connected
@Override
protected void onPreExecute()
{
progress = ProgressDialog.show(CarControl.this, "Connecting...", "Please wait!!!");  //show a progress dialog
}

@Override
protected Void doInBackground(Void... devices) //while the progress dialog is shown, the connection is done in background
{
try
{
if (btSocket == null || !isBtConnected)
{
myBt = BluetoothAdapter.getDefaultAdapter();//get the mobile bluetooth device
BluetoothDevice dispositivo = myBt.getRemoteDevice(address);//connects to the device's address and checks if it's available
btSocket = dispositivo.createRfcommSocketToServiceRecord(myUUID);//create a RFCOMM (SPP) connection
BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
btSocket.connect();//start connection
}
}
catch (IOException e)
{
ConnectSuccess = false;//if the try failed, you can check the exception here
}
return null;
}
@Override
protected void onPostExecute(Void result) //after the doInBackground, it checks if everything went fine
{
super.onPostExecute(result);
if (!ConnectSuccess)
{
msg("Connection Failed. Is it a SPP Bluetooth? Try again.");
finish();
}
else
{
msg("Connected.");
isBtConnected=true;
}
progress.dismiss();
}
}

}

这意味着程序的内存限制是6mb,当达到内存限制时程序抛出错误,因为它不能接受进一步的命令。我想没有直接的方法来增加这个限制。

最新更新