我对 Java 和 Android 还是很陌生,所以要温柔:) 我试图启动 ActivityForResult 以启用蓝牙,但似乎主要活动继续运行并执行 getPaireddevices 而无需等待 ActivityForresult 完成。我的错误是什么?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
if (BtAdapter==null){
Toast.makeText(getApplicationContext(), "No Bluetooth adapter...",0 ).show();
finish();
} else {
if (!BtAdapter.isEnabled()){
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, 1);
}
}
GetPairedDevices();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
//super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_CANCELED){
Toast.makeText(getApplicationContext(), "too bad..", Toast.LENGTH_LONG).show();
finish();
}
}