大家好..。我是Android应用程序开发的新手。目前,我正在与BITalino的Android一起开发我自己的生物信号应用程序。当我按下“开始”按钮时,我现在面临的问题.其中打算转移到下一个活动,它带我回到启动活动(主要活动),.No错误或警告发出。只是不像它应该的工作方式
下面是代码
谢谢你.
manifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Holo.Light">
<activity
android:name=".ScanActivity"
android:label="Anhalt BITadroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DeviceActivity" />
<activity android:name=".BiosignalDisplay"></activity>
</application>onClick()用于Device_Activity(MainActivity)的片段
public class DeviceActivity extends Activity implements OnBITalinoDataAvailable, View.OnClickListener {
private final String TAG = this.getClass().getSimpleName();
public final static String EXTRA_DEVICE = "info.plux.pluxapi.sampleapp.DeviceActivity.EXTRA_DEVICE";
public final static String FRAME = "info.plux.pluxapi.sampleapp.DeviceActivity.Frame";
private BluetoothDevice bluetoothDevice;
private BITalinoCommunication bitalino;
private boolean isBITalino2 = false;
private Handler handler;
private States currentState = States.DISCONNECTED;
private boolean isUpdateReceiverRegistered = false;
/*
* UI elements
*/
private TextView nameTextView;
private TextView addressTextView;
private TextView elapsedTextView;
private TextView stateTextView;
private Button connectButton;
private Button disconnectButton;
private Button startButton;
private Button stopButton;
private LinearLayout bitalinoLinearLayout;
private Button stateButton;
private RadioButton digital1RadioButton;
private RadioButton digital2RadioButton;
private RadioButton digital3RadioButton;
private RadioButton digital4RadioButton;
private Button triggerButton;
private SeekBar batteryThresholdSeekBar;
private Button batteryThresholdButton;
private SeekBar pwmSeekBar;
private Button pwmButton;
private TextView resultsTextView;
private boolean isDigital1RadioButtonChecked = false;
private boolean isDigital2RadioButtonChecked = false;
private float alpha = 0.25f;
/*
* Test with 2 device
*/
// private BITalinoCommunication bitalino2;
// private String identifierBITalino2 = "20:16:07:18:15:94";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(getIntent().hasExtra(EXTRA_DEVICE)){
bluetoothDevice = getIntent().getParcelableExtra(EXTRA_DEVICE);
}
initView();
setUIElements();
handler = new Handler(getMainLooper()){
@Override
public void handleMessage(Message msg) {
Bundle bundle = msg.getData();
BITalinoFrame frame = bundle.getParcelable(FRAME);
Log.d(TAG, frame.toString());
if(frame != null){ //BITalino
resultsTextView.setText(frame.toString());
}
}
};
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(updateReceiver, makeUpdateIntentFilter());
isUpdateReceiverRegistered = true;
}
@Override
protected void onDestroy() {
super.onDestroy();
if(isUpdateReceiverRegistered) {
unregisterReceiver(updateReceiver);
isUpdateReceiverRegistered = false;
}
if(bitalino != null){
bitalino.closeReceivers();
try {
bitalino.disconnect();
} catch (BITalinoException e) {
e.printStackTrace();
}
}
// if(bitalino2 != null){
// bitalino2.closeReceivers();
// try {
// bitalino2.disconnect();
// } catch (BITalinoException e) {
// e.printStackTrace();
// }
// }
}
/*
* UI elements
*/
private void initView(){
nameTextView = (TextView) findViewById(R.id.device_name_text_view);
addressTextView = (TextView) findViewById(R.id.mac_address_text_view);
elapsedTextView = (TextView) findViewById(R.id.elapsed_time_Text_view);
stateTextView = (TextView) findViewById(R.id.state_text_view);
connectButton = (Button) findViewById(R.id.connect_button);
disconnectButton = (Button) findViewById(R.id.disconnect_button);
startButton = (Button) findViewById(R.id.start_button);
stopButton = (Button) findViewById(R.id.stop_button);
//bitalino ui elements
bitalinoLinearLayout = (LinearLayout) findViewById(R.id.bitalino_linear_layout);
stateButton = (Button) findViewById(R.id.state_button);
digital1RadioButton = (RadioButton) findViewById(R.id.digital_1_radio_button);
digital2RadioButton = (RadioButton) findViewById(R.id.digital_2_radio_button);
digital3RadioButton = (RadioButton) findViewById(R.id.digital_3_radio_button);
digital4RadioButton = (RadioButton) findViewById(R.id.digital_4_radio_button);
triggerButton = (Button) findViewById(R.id.trigger_button);
batteryThresholdSeekBar = (SeekBar) findViewById(R.id.battery_threshold_seek_bar);
batteryThresholdButton = (Button) findViewById(R.id.battery_threshold_button);
pwmSeekBar = (SeekBar) findViewById(R.id.pwm_seek_bar);
pwmButton = (Button) findViewById(R.id.pwm_button);
resultsTextView = (TextView) findViewById(R.id.results_text_view);
}
private void setUIElements(){
if(bluetoothDevice.getName() == null){
nameTextView.setText("BITalino");
}
else {
nameTextView.setText(bluetoothDevice.getName());
}
addressTextView.setText(bluetoothDevice.getAddress());
stateTextView.setText(currentState.name());
Communication communication = Communication.getById(bluetoothDevice.getType());
Log.d(TAG, "Communication: " + communication.name());
if(communication.equals(Communication.DUAL)){
communication = Communication.BLE;
}
bitalino = new BITalinoCommunicationFactory().getCommunication(communication,this, this);
// bitalino2 = new BITalinoCommunicationFactory().getCommunication(communication,this, this);
connectButton.setOnClickListener(this);
disconnectButton.setOnClickListener(this);
startButton.setOnClickListener(this);
stopButton.setOnClickListener(this);
stateButton.setOnClickListener(this);
digital1RadioButton.setOnClickListener(this);
digital2RadioButton.setOnClickListener(this);
digital3RadioButton.setOnClickListener(this);
digital4RadioButton.setOnClickListener(this);
triggerButton.setOnClickListener(this);
batteryThresholdButton.setOnClickListener(this);
pwmButton.setOnClickListener(this);
}
/*
* Local Broadcast
*/
private final BroadcastReceiver updateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if(ACTION_STATE_CHANGED.equals(action)){
String identifier = intent.getStringExtra(IDENTIFIER);
States state = States.getStates(intent.getIntExtra(EXTRA_STATE_CHANGED, 0));
Log.i(TAG, identifier + " -> " + state.name());
stateTextView.setText(state.name());
switch (state){
case NO_CONNECTION:
break;
case LISTEN:
break;
case CONNECTING:
break;
case CONNECTED:
break;
case ACQUISITION_TRYING:
break;
case ACQUISITION_OK:
break;
case ACQUISITION_STOPPING:
break;
case DISCONNECTED:
break;
case ENDED:
break;
}
}
else if(ACTION_DATA_AVAILABLE.equals(action)){
if(intent.hasExtra(EXTRA_DATA)){
Parcelable parcelable = intent.getParcelableExtra(EXTRA_DATA);
if(parcelable.getClass().equals(BITalinoFrame.class)){ //BITalino
BITalinoFrame frame = (BITalinoFrame) parcelable;
resultsTextView.setText(frame.toString());
}
}
}
else if(ACTION_COMMAND_REPLY.equals(action)){
String identifier = intent.getStringExtra(IDENTIFIER);
if(intent.hasExtra(EXTRA_COMMAND_REPLY) && (intent.getParcelableExtra(EXTRA_COMMAND_REPLY) != null)){
Parcelable parcelable = intent.getParcelableExtra(EXTRA_COMMAND_REPLY);
if(parcelable.getClass().equals(BITalinoState.class)){ //BITalino
Log.d(TAG, ((BITalinoState)parcelable).toString());
resultsTextView.setText(parcelable.toString());
}
else if(parcelable.getClass().equals(BITalinoDescription.class)){ //BITalino
isBITalino2 = ((BITalinoDescription)parcelable).isBITalino2();
resultsTextView.setText("isBITalino2: " + isBITalino2 + "; FwVersion: " + String.valueOf(((BITalinoDescription)parcelable).getFwVersion()));
// if(identifier.equals(identifierBITalino2) && bitalino2 != null){
// try {
// bitalino2.start(new int[]{0,1,2,3,4,5}, 1);
// } catch (BITalinoException e) {
// e.printStackTrace();
// }
// }
}
}
}
}
};
private IntentFilter makeUpdateIntentFilter() {
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION_STATE_CHANGED);
intentFilter.addAction(ACTION_DATA_AVAILABLE);
intentFilter.addAction(ACTION_EVENT_AVAILABLE);
intentFilter.addAction(ACTION_DEVICE_READY);
intentFilter.addAction(ACTION_COMMAND_REPLY);
return intentFilter;
}
/*
* Callbacks
*/
@Override
public void onBITalinoDataAvailable(BITalinoFrame bitalinoFrame) {
Message message = handler.obtainMessage();
Bundle bundle = new Bundle();
bundle.putParcelable(FRAME, bitalinoFrame);
message.setData(bundle);
handler.sendMessage(message);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.connect_button:
try {
bitalino.connect(bluetoothDevice.getAddress());
} catch (BITalinoException e) {
e.printStackTrace();
}
break;
case R.id.disconnect_button:
try {
bitalino.disconnect();
} catch (BITalinoException e) {
e.printStackTrace();
}
break;
case R.id.start_button:{
Intent Recordingintent = new Intent(getApplicationContext(), BiosignalDisplay.class);
startActivity(Recordingintent);}
break;
case R.id.stop_button:
Intent exit = new Intent(this, ScanActivity.class);
startActivity(exit);
break;
}
}
}main.xmlenter code here
发布于 2018-02-23 11:14:59
这个问题实际上不能用提供的信息来回答,所以我将给出一些关于如何根据评论中提供的上下文找到这些类型的问题和实际解决方案的一般性指导。
如果你的应用程序在你没有预料到的时候关闭了,那么通常的原因是它是一个不显眼的RuntimeException。与“检查例外情况”不同的是,为了使编译器高兴,它们不需要被尝试捕获所包围。如果它们未被捕获,它们将终止程序/应用程序。
修复这些异常的第一步是检查Android (Log )中的异常和堆栈跟踪。在Android中,日志输出位于左下角。
如果日志非常繁忙,那么您可以通过类型和应用程序对其进行筛选。为了找出错误,我们通过应用程序和“错误”日志级别进行过滤。
问题的实际例外(从评论中)是:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.这(很可能)意味着BiosignalDisplay-activity从Android支持库扩展了AppCompactActivity,但是AndroidManifest.xml中的条目没有为活动设置支持库主题。
可以通过将theme-attribute设置在特定的<activity>-tag上或在<application>-tag上设置为Theme.AppCompat下的任何主题来解决这个问题,例如,Theme.AppCompat.Light.NoActionBar。
有关此问题的更多信息,请参见:您需要在此活动中使用Theme.AppCompat主题(或后代)。
https://stackoverflow.com/questions/48925700
复制相似问题