Hellow everyone ... I'm new to Android Application development .. Currently I'm working with BITalino Android API to develop my own Biosignal App. The issue I'm facing now when I press the start button ... which intended to move to the next Activity it take me back to the launcher Activity(Main Activity).No error or warning is given out .. its just not working the way it supposed to work
Below are the codes
Thank you very much in advance .....
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>
Snippet of onClick() for 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