I have a small problem with an activity.
There are 3 activities:
MainActivity for a login,
DataActivity is an activity with 3 tabs,
ParameterActivity is an activity to change settings.
These are the steps to the problem:
- The App is started an the MainActivity is loaded
- The user press on a login button and the DataActivity is loaded
- The user press the "Back" button on the device (a tablet) and the ParameterActivity is loaded. -> but the ParameterActivity is not loaded properly. It is only shown, steps in OnCreate are not performed.
Why step 3?
In my code there is only one possibility where the activity is loaded (there is a "Parameter" button in the MainActivity, added with setOnClickListener in OnCreate).
In background (started in MainActivity) there is a thread which checks for data connection to a server.
This is the code of the Login button.
It doesn't matter if the App is running in simulation or normal mode. The other code is for checking of the right pin (format and value). PasswordTimeOut(), WrongPasswordMessage(), PasswordFalschesFormat() are functions to show a message.
bLogin.setOnClickListener(new View.OnClickListener() {
//On Click Methode
@Override
public void onClick(View v) {
// Checkbox fürs Passwort gesetz
if (chkPW.isChecked()) {
ZGlobals.setting.setPin(txtPin.getText().toString());
}
else { // sonst Pin zurücksetzen
ZGlobals.setting.setPin("");
}
SaveSettings();
// Wenn Simulationsmodus, dann direkt Hauptmaske, wenn PIN 1234 richtig
if (ZGlobals.setting.getSimulation()) {
if (txtPin.getText().toString().length() == 4 && isNumeric(txtPin.getText().toString())){
if (Integer.parseInt(txtPin.getText().toString()) == 1234) {
bLayoutThread = false;
Intent i = new Intent(getApplicationContext(), HomescreenActivity.class);
startActivity(i);
} else {
WrongPasswordMesage();
}
}
else {
PasswordFalschesFormat();
}
} else {
Runnable ReadData = new Runnable() {
@Override
public void run () {
int iCount = 0;
ZGlobals.gui.ResetPasswordMessage();
while (!ZGlobals.gui.GetMessagePasswordReceived()) {
iCount++;
if (iCount == 100) {
break;
}
SystemClock.sleep(20);
}
if (iCount < 100) {
if (ZGlobals.gui.GetMessagePasswordReceived()) {
if (ZGlobals.gui.getMessagePassword().getPasswordCorrect()) {
RightPasswordMessage();
bLayoutThread = false;
Intent i = new Intent(getApplicationContext(), HomescreenActivity.class);
startActivity(i);
}
else {
WrongPasswordMesage();
}
}
} // end if
else {
PasswordTimeOut ();
}
}
};
if (checkPin(txtPin.getText().toString())) {
Thread t = new Thread(ReadData);
t.start();
}
}
} // onClick
});
In the second activity the onBack is not overrided.