Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:51:50+00:00 2026-06-16T17:51:50+00:00

I want to implement a password change activity in my application, and here is

  • 0

I want to implement a password change activity in my application, and here is the code which I’ve written for my activity, but I think that I should declare the String Password variable to somewhere else, because my new password changes successfully and works until I close the application,and when I run it again the old password is the right one.I’m really new to Android development, any answers/suggestions will be appreciated.

Change_Password code:

public class Change_Password extends Activity {
    //----
     public SharedPreferences prefs;
      private String prefName = "MyPref";
      private static final String TEXT_VALUE_KEY = "nothing";
      //-----

    public static String Password="soha";

        public static String getPassword()
        {
            return Password;
        }


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.change_password);


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

        public void onClick(View arg0) {

            finish();
        }
    });

    final EditText txtNewPassword=(EditText)findViewById(R.id.txtNewPassword);
    final EditText txtCurrentPassword=(EditText)findViewById(R.id.txtCurrentPassword);
    final EditText txtConfirmPassword=(EditText)findViewById(R.id.txtConfirmNewPassword);
    Button btnSave=(Button)findViewById(R.id.btnSave);
    btnSave.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            if(txtConfirmPassword.getText().toString().equalsIgnoreCase("") |
                    txtCurrentPassword.getText().toString().equalsIgnoreCase("") |
                    txtCurrentPassword.getText().toString().equalsIgnoreCase(""))
                {
                    Toast.makeText(getBaseContext(),"Please Complete the Information", Toast.LENGTH_SHORT).show();
                }
                 else
                 if(!txtNewPassword.getText().toString().equalsIgnoreCase(txtConfirmPassword.getText().toString()))
                  {
                    Toast.makeText(getBaseContext(),
                    "These Passwords Don't Match !", Toast.LENGTH_SHORT).show();
                   }
                 else
                 if(!getPassword().equalsIgnoreCase(txtCurrentPassword.getText().toString()))
                    {
                         Toast.makeText(getBaseContext(),
                            "Current Password is Incorrect!", Toast.LENGTH_SHORT).show();
                     }
                   else
                    {
                     ///------- //---save the values in the EditText view to preferences---  
                    prefs = getPreferences(MODE_PRIVATE);
                     SharedPreferences.Editor editor = prefs.edit();
                     editor.putString(TEXT_VALUE_KEY, txtNewPassword.getText().toString());
                     //---saves the values---
                        editor.commit();       
                     ///--------
                      //Password=txtNewPassword.getText().toString();
                      Toast.makeText(getBaseContext(),
                              Password, Toast.LENGTH_SHORT).show();
                      }

                 }
           });

}

@Override
public void onAttachedToWindow() {
   this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
  super.onAttachedToWindow();


}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
   if(keyCode == KeyEvent.KEYCODE_HOME)

       BackToMainIntent();

 else if(keyCode==KeyEvent.KEYCODE_BACK)
   {
     BackToMainIntent();
  }
   return false;
}



public void BackToMainIntent()
{
    Intent intent = new Intent(this, Main.class);
       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
       startActivity(intent);
  }
}

And Here my main activity:

 public class mainC extends Activity {



        private EditText uPass;
        private Button loginBtn;
        private Button Btn_Exit;
        private ImageView Image;

        ///------
        public SharedPreferences prefs;
        private String prefName = "MyPref";
        private static final String TEXT_VALUE_KEY = "1234";
        ////----------
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.loginpage);

            Image=(ImageView)findViewById(R.id.NFCImage);
            Image.setAlpha(100);
            Btn_Exit=(Button)this.findViewById(R.id.Btn_exit_app);
            Btn_Exit.setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {


                    Intent _Intent =new Intent(Intent.ACTION_MAIN);
                    _Intent.addCategory(Intent.CATEGORY_HOME);
                    _Intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(_Intent);

                }
            });

            setUpViews();
        }
        @Override
        protected void onResume() {
            super.onResume();

            uPass.setText("");

            uPass.setInputType(InputType.TYPE_CLASS_TEXT| InputType.TYPE_TEXT_VARIATION_PASSWORD);
            uPass.setTextColor(Color.parseColor("#888888"));
        }
        private void setUpViews() {

             uPass=(EditText)findViewById(R.id.usrPassTxt);

            uPass.setOnFocusChangeListener(new View.OnFocusChangeListener(){

                public void onFocusChange(View v, boolean hasFocus) {

                        if(hasFocus){
                            uPass.setInputType(InputType.TYPE_CLASS_TEXT| InputType.TYPE_TEXT_VARIATION_PASSWORD);

                            uPass.setText("");
                        }
                }


            });


            loginBtn=(Button)findViewById(R.id.Btn_Login);


              loginBtn.setOnClickListener(new OnClickListener() {
                private String pass;

                Intent myIntent;

                public void onClick(View v) {

                    pass=uPass.getText().toString();

                    ///-----
                    SharedPreferences prefs = getSharedPreferences(prefName, MODE_PRIVATE);
                    String passtemp = prefs.getString(TEXT_VALUE_KEY, "nothing");
                    if( pass.equalsIgnoreCase(passtemp)) 
                    ///-----
                    //if( pass.equalsIgnoreCase(Change_Password.getPassword()))
                    {
                        myIntent=new Intent(mainC.this,Main.class);
                        myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        System.out.println("---IF---");
                    }

                    else{
                        myIntent=new Intent(mainC.this,ErrorPage.class);


                        System.out.println("---ELSE---");
                    }

                    startActivity(myIntent);
                }
            });
        }
        @Override
        public void onBackPressed() {

            finish();
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:51:52+00:00Added an answer on June 16, 2026 at 5:51 pm

    The problem here is that your are running all in memory, I mean, you have your Password variable (static) in memory, you assigned it when the password is changed and its ok.

    But when you start the appliccation again, the value of password is 1234 because you have code it! xD, you have to store de password somewhere else, for example using SharedPreferences.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to change main activity at application startup in Android? I want to implement
I want to implement an application which will work as a parser. User will
I want to implement a forgot-password feature in asp.net mvc that allows users to
I have my own password/login rules that I want to implement such as: Password:
I have a button which I want to implement with password before triggering a
I want implement in my software solution an VBA editor but in c# 3.0.
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
I want to implement a job scheduler in my windows azure application. My aim
I want to implement login using facebook in my windows phone 7.1 application When
I want to implement Facebook Connect in my android application. I have seen a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.