0

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:

  1. The App is started an the MainActivity is loaded
  2. The user press on a login button and the DataActivity is loaded
  3. 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.

nunofmendes
  • 3,731
  • 2
  • 32
  • 42
Selucky
  • 3
  • 3
  • 3
    A small problem with the question.. no relevant code to find 'why step 3' – Pararth Nov 03 '14 at 13:11
  • Set a breakpoint and examine what happens when you click "Back" button. – Marius Nov 03 '14 at 13:14
  • Which code do you need? I think if I post all code it's a little bit to much :) If I set a breakpoint I cannot see anything special. The current activity is closed. – Selucky Nov 03 '14 at 13:22
  • paste complete code of navigationand also of backpress method if have any.. – Pankaj Arora Nov 03 '14 at 13:24
  • Did you override onBackPressed()? This is where you control what happens when you press back. – Booger Nov 03 '14 at 13:43
  • No, onBackPressed is not overrided. – Selucky Nov 03 '14 at 13:49
  • 1
    What makes you think the `ParameterActivity` will be started when you use the BACK key? That isn't normal behaviour. The default behaviour of the BACK key is that it finishes the current activity and returns to the previous activity in the stack. – David Wasser Nov 03 '14 at 17:13
  • Ok, it's not the Activity which is started, but the layout is shown. The layout is without any function. If a button is pushed nothing happend (I set breakpoints in the methods). – Selucky Nov 04 '14 at 06:52

1 Answers1

0

I've found the mistake. The overrided method onResume was implemented in the class which set the other layout.

I didn't implemented it, it was my teammate and he is on a yourney. Don't know why he implemented it...

Sorry for asking such a stupid question...

Selucky
  • 3
  • 3