I got android app based on 2 activities. The Main activity is just a input field and a button to get some user information. When the user press the button a barcodescanner (ZXING) will start.
Every thing works perfect. But know i try to check in the onCreate if user information is already known. If its true -> start the barcodescanner. But it looks like the barcodescanner activity starts up twice, because:
pressing back button once: annother barcodescanner wil be active.
pressing back button twice: Main activty will be active.
this is the check inside onCreate:
if(pref.length() == 6){
startActivityForResult(intent, 0);
}
and this is the function called when clicking the button:
public void onClick(View view) {
switch (view.getId()) {
case R.id.button1:
final EditText edit = (EditText) findViewById(R.id.panelID);
if(edit.getText().toString().length() == 6){
String temp = edit.getText().toString();
Log.e("click", temp);
Editor e = this.getPreferences(Context.MODE_PRIVATE).edit();
e.putString("panelID", temp);
e.commit();
startActivityForResult(intent, 0);
} else {
Toast.makeText(this, "Ongeldige invoer (6 cijfer id)", Toast.LENGTH_LONG).show();
}
break;
}
}
What do i do wrong?
Your trouble seems to be more with how you are managing the lifecycle of the activity. If you post your Activity’s onCreate() method’s code, we might be able to see better what you’re trying to accomplish and suggest a solution accordingly.