1

I am developing an application with 5 interfaces

I have an activity where the user has to enter a password, after entering it the user moves to the next activity, but when the user clicks on back button and he's returned to the password activity, the entered password is missing... how can I maintain the entered password?

Code:

back = (Button) findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener() {    

        public void onClick(View v1) {
            Intent backIntent = new Intent();
            backIntent.setClass(getApplicationContext(), LockAppActivity.class);
            backIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
            startActivity(backIntent);
            finish();
        }
    });

Suppose the app starts with activities A --> B --> C --> D --> E

When user moves to B from C, and at activity B there is a "deactivate" button and when the user presses it all the user settings are cleared and the application will exit, but when I press the button, it brings me to the layout C... how can I change this?

    deactivate = (Button) findViewById(R.id.deactivate);
    deactivate.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v){ 
            final String STORAGE = "UniqueID_IMSI";
            SharedPreferences unique = getSharedPreferences(STORAGE, 0);
            SharedPreferences.Editor editor1 = unique.edit();
            editor1.putString("identifier", "");
            editor1.putString("simIMSI", "");
            editor1.commit();

            final String LOGIN_PASSWORD = "Login_Password";     
            SharedPreferences loginPassword = getSharedPreferences(LOGIN_PASSWORD, 0);
            SharedPreferences.Editor editor2 = loginPassword.edit();
            editor2.putString("loginPassword", "");
            editor2.commit();

            final String LOCK_APP_PASSWORD = "LockAppPassword";
            SharedPreferences userPassword = getSharedPreferences(LOCK_APP_PASSWORD, 0);
            SharedPreferences.Editor editor3 = userPassword.edit();
            editor3.putString("password", "");
            editor3.commit();

            final String PHONE_NUMBER = "Phone_Number";         
            SharedPreferences phone = getSharedPreferences(PHONE_NUMBER, 0);
            SharedPreferences.Editor editor4 = phone.edit();
            editor4.putString("phoneNumber", "");
            editor4.commit();

            finish();
        }
    });
}
keyser
  • 18,829
  • 16
  • 59
  • 101
Android_Rookie
  • 509
  • 2
  • 10
  • 25

2 Answers2

1

how can i maintain the entered password

Save the password entered by the user in a SharedPreference and in onResume() function of the Activity recalled the saved password from the SharedPrefrence and show it to user. You may like to spend sometime trying to understand the Activity lifecycle.

application will exit

Have a look at this link. @Romain Guy, is a Google guy. You may wish to rethink about your app design.

Community
  • 1
  • 1
Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
0

my favorite solution to the closing-app problem are:

  • consider using "startActivityForResult" for activities that you wish to close when a specific event has occurred .
  • you can also use some intents flags , but i consider them quite messy and try to use as little of them as possible
  • use fragments instead of activities . you can choose exactly which fragment to show and when.
android developer
  • 114,585
  • 152
  • 739
  • 1,270