I strucked in storing and getting shared preferences.When a user has been registered if that registration is success then that values has to be stored in his profile nothing but
To save value:
@Override
protected void onPostExecute(String s) {
pd.dismiss();
if("SUCCESS".equals(jsonresponce)){
Toast.makeText(getApplicationContext(),jsonresponce,Toast.LENGTH_SHORT).show();
SharedPreferences sharedpreferences = getSharedPreferences("a2a", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("enteredfname", enteredfname);
editor.putString("enteredlname", enteredlname);
editor.commit();
}else{
Toast.makeText(getApplicationContext(),jsonresponce,Toast.LENGTH_SHORT).show();
}
super.onPostExecute(s);
}
}
To retrive value:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_myprofile, container, false);
mfname = (EditText)rootView.findViewById(R.id.fname);
mlname = (EditText)rootView.findViewById(R.id.lname);
mcontact = (EditText)rootView.findViewById(R.id.contact);
mpassword = (EditText)rootView.findViewById(R.id.editpass);
SharedPreferences sharedpreferences = getSharedPreferences("a2a", Context.MODE_PRIVATE)
value = sharedpreferences.getString("enteredfname", "enteredfname")
mfname.setText(value);
return rootView;
}