I've created a shared preference screen on android to receive info from the shared preference screen to the main screen, every thing is working fine, but the the values in the preference screen aren't saved , and every time I must open the shared preference screen and type the info manualy ... any suggestions to auto save the preferences?
this is the shared perefrence code:
Button b1 = (Button)findViewById(R.id.SavePreff);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String ID_NO = ID_NUMBER.getText().toString();
SharedPreferences prefsExample = getSharedPreferences(PREFS, 0);
SharedPreferences.Editor editor = prefsExample.edit();
editor.putString("idNumber", ID_NO);
if (rd1.isChecked())
editor.putString("Network", "STC");
else if (rd2.isChecked())
editor.putString("Network", "Mobily");
else
editor.putString("Network", "Zain");
editor.commit();
Intent i = new Intent(SharedPref.this , MainActivity.class);
startActivity(i);
}
});
and this is the main activity screen that I'm using the info from it :
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences example = getSharedPreferences(PREFS, 0);
String ID_NUM = example.getString("idNumber", "123432");
String NETWORK = example.getString("Network", "STC");
String called_num = "";
if (NETWORK.equals("Mobily"))
called_num = "*1400*" + CODE_CHARGE.getText().toString() + "*"+ ID_NUM+ Uri.encode("#");
else if (NETWORK.equals("STC"))
called_num = "*155*" + CODE_CHARGE.getText().toString() + "*"+ ID_NUM+ Uri.encode("#");
else if (NETWORK.equals("Zain"))
called_num = "*141*" + ID_NUM + "*"
+ CODE_CHARGE.getText().toString()+ Uri.encode("#");
Intent i = new Intent("android.intent.action.CALL");
Uri data = Uri.parse("tel:" + called_num);
i.setData(data);
startActivity(i);
}
});