I want to Save the User data in app as a One time activity so that it will not ask again and I have Given like this...
public class Main_A extends Activity {
public static final String Sh_Pref = "Sh_Pref_data";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.s_pref);
SharedPreferences settings = getSharedPreferences(Sh_Pref, 0);
HashMap<String, String> map = (HashMap<String, String>) settings.getAll();
if (map != null && (map.containsKey("dtype") && map.containsKey("user_id") && map.containsKey("gname")&& map.get("dtype") != null && map.get("user_id") != null && map.get("gname") != null ))
{
Main_A.this.finish();
Intent ss = new Intent(Main_A.this, Splash.class);
ss.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
ss.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ss.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
ss.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(ss);
}
else {
Button b = (Button) findViewById(R.id.save);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Spinner dtype = (Spinner) findViewById(R.id.s1);
EditText user_id = (EditText) findViewById(R.id.et1);
Spinner gname = (Spinner) findViewById(R.id.s2);
Spinner utype = (Spinner) findViewById(R.id.s3);
Spinner ttype = (Spinner) findViewById(R.id.s4);
if (dtype.getSelectedItem().toString().length() > 0 && user_id.getText().toString().length() > 0 && user_id.getText().toString().length() > 0 && utype.getSelectedItem().toString().length() > 0 && ttype.getSelectedItem().toString().length() > 0 && dtype.getSelectedItem().toString().length() > 0) {
String ct=dtype.getSelectedItem().toString();
String dom = user_id.getText().toString();
String am=gname.getSelectedItem().toString();
String ut=utype.getSelectedItem().toString();
String aname = getString(taname);
if(ut.equals("Talent"))
{
ut="T";
}
else if(ut.equals("A+"))
{
ut="A";
}
else if(ut.equals("Saint"))
{
ut="S";
}
String tt=ttype.getSelectedItem().toString();
Map<String, String> map = new HashMap<String, String>();
SharedPreferences settings = getSharedPreferences(Sh_Pref, 0);
SharedPreferences.Editor editor = settings.edit();
map.put("dtype",ct);
map.put("user_id", dom);
map.put("gname",am);
for (String key : map.keySet()) {
editor.putString(key, map.get(key));
}
editor.commit();
Main_A.this.finish();
Intent i = new Intent(Main_A.this, Splash.class);
startActivity(i);
}
}
});
Button c = (Button) findViewById(R.id.cancel);
c.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Main_A.this);
alertDialogBuilder.setTitle("ⓘ Exit ! " + getString(R.string.app_name));
alertDialogBuilder
.setMessage(Html.fromHtml("<p style='text-align:center;'>Please Fill the required details</p><h3 style='text-align:center;'>Click Yes to Exit !</h4>"))
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
});
}
}
@Override
public void onBackPressed() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("ⓘ Exit ! " + getString(R.string.app_name));
alertDialogBuilder
.setMessage(Html.fromHtml("<p style='text-align:center;'>Please Fill the required details</p><h3 style='text-align:center;'>Click Yes to Exit !</h4>"))
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
Here Its saving all the Data and Running Successfully
Here I want to Edit the Same file in a different Activity.. But I need to View and what are previous values...
Because its a One time activity...After that app start...... So that If any thing is wrong Edit only that particular value...
Due to wrong details app may case errors.. for this user need to Clear cache/data or Uninstall and re install.. so To avoid This I want to add a Edit for Shared prefs..
Can any one suggest me on this kind