Showing posts with label How to change Pin Number using sharedpreferences in Android?. Show all posts
Showing posts with label How to change Pin Number using sharedpreferences in Android?. Show all posts

Tuesday, April 9, 2013

[android help] How to change Pin Number using sharedpreferences in Android?


I'm having implement android demo for application pin using shared preferences which i enter pin and confirm the pin.The problem is that when I am accessing this values, it is not returning updated values, it gives me NullPointerException.


String strGetPin;



public final String pref_filename = "settings";
String myPassword;
static SharedPreferences shaedPref;
public static String strdataReturned = "";


public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_list);
activity=this;


edtxt_EnterPin =(EditText)findViewById(R.id.edtxt_Pin);
edtxt_NewPin =(EditText)findViewById(R.id.edtxt_NewPin);
edtxt_ConfirmPin=(EditText)findViewById(R.id.edtxt_ConfirmPin);
shaedPref = getSharedPreferences(pref_filename, 0);
strdataReturned = shaedPref.getString("user", "");

if (strdataReturned.equals(""))
{
SharedPreferences.Editor editor = shaedPref.edit();
editor.putString("user", "1234"); // newData is new pass,passwordKey is key
editor.commit();
}




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

@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
myDialog=new Dialog(Settings_Activity.this);
myDialog.setContentView(R.layout.pin_change);
myDialog.setTitle("Application PIN Change");
myDialog.setCancelable(false);





//Button For Change Pin save
Button btnChange=(Button) myDialog.findViewById(R.id.btn_Save);
btnChange.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub


String stringData = edtxt_EnterPin.getText().toString().trim();
strdataReturned = shaedPref.getString("user", ""); // key/def message

// if stored password is equal to entered password
if (strdataReturned.equals(stringData))

{
String newData = edtxt_NewPin.getText().toString().trim();
SharedPreferences.Editor editor = shaedPref.edit();
editor.putString("user", newData); // newData is new pass, passwordKey is key
editor.commit();


Toast.makeText(getApplicationContext(),"PIN Change successfully", Toast.LENGTH_LONG).show();
edtxt_EnterPin.setText("");
edtxt_NewPin.setText("");
}

else

{
Toast.makeText(getApplicationContext(), "Wrong Pin!",Toast.LENGTH_LONG).show();
edtxt_EnterPin.setText("");
edtxt_NewPin.setText("");
}




}
});



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

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
myDialog.dismiss();
}
});

myDialog.show();



}
});


}



.

stackoverflow.comm

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...