sir, how do i save the changes made in my change password activity if i changed to another activity. at first, i’ve tried to just use a variable to save the values, but if i return to other activity all changes made comes back to normal. i’ve tried to use arraylist but it’s the same. can you teach me other methods of creating a change password option. thanks for help in advance.
public class ChangePassword extends Activity {
/** Called when the activity is first created. */
EditText enterPassword, enterNewPassword;
String defaultPassword = "1234";
ArrayList<String> newPasswordArray = new ArrayList<String>();
ArrayList<String> currentPasswordArray = new ArrayList<String>();
String newPassword;
String currentPassword;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.changepassword);
Button save = (Button)findViewById(R.id.btnSaveSettings);
enterPassword = (EditText)findViewById(R.id.etEnterPassword);
enterNewPassword = (EditText)findViewById(R.id.etNewPassword);
currentPasswordArray.add("1234");
for(String s: newPasswordArray)
{
newPassword = s;
}
for(String s: currentPasswordArray)
{
currentPassword = s;
}
save.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0) {
// TODO Auto-generated method stub
try
{
//get string from arraylist
for(String s: newPasswordArray)
{
newPassword = s;
}
for(String s: currentPasswordArray)
{
currentPassword = s;
}
//test password
if(enterPassword.getText().toString().equals(currentPassword))
{
if(enterNewPassword != null)
{
String newPass = setNewPassword(enterNewPassword.getText().toString());
setCurrentPassword(newPass);
Toast.makeText(getApplicationContext(), "Save Success", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Please fill up all fields.", Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(getApplicationContext(), "Current password, unmatched.", Toast.LENGTH_LONG).show();
}
}
catch(Exception e)
{
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Save failed", Toast.LENGTH_LONG).show();
}
}
});
}//oncreate()
public String setNewPassword(String pass)
{
String returnPass = "";
newPasswordArray.clear();
newPasswordArray.add(pass);
for(String s : newPasswordArray)
{
returnPass = s;
}
return returnPass;
}//setNewPassword()
public String getPassword()
{
return newPassword;
}//getPassword
public void setCurrentPassword(String newpass)
{
currentPasswordArray.clear();
currentPasswordArray.add(newpass);
}//setCurrentPassword
}
You must use one of the 3 ways that Android platform provides, to save your data:
If you just want to save and resume again.
But if you just want to save the instance of your activity then you can just override the appropriate methods.