I am trying to implement a SharedPreferences
.
I already search it, try it, for almost 12 hours and its still cannot help my problem.
Java Code
public static final String MyPREFERENCES = "banner_pref" ;
SharedPreferences SharedP;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedP = getSharedPreferences("banner_pref", MainHelloballi.MODE_PRIVATE);
SharedPreferences.Editor editor = SharedP.edit();
editor.putBoolean("banner_pref", true);
editor.commit();
Boolean myValue = SharedP.getBoolean("banner_pref", true);
if (myValue == true){
bannerfull = (RelativeLayout) findViewById(R.id.banner_full);
bannerfull.setVisibility(View.VISIBLE);
editor = SharedP.edit();
editor.putBoolean("banner_pref", false);
editor.commit();
}
else {
bannerfull = (RelativeLayout) findViewById(R.id.banner_full);
bannerfull.setVisibility(View.GONE);
//SharedP.edit().putBoolean("banner_pref", false).commit();
}
}
I know that my SharedPreferences
value is keep True
. So my question is, how to make it not true when I open the same Activity
?
I really appriciate it if anyone can give me a sample from my code. So I can learn from it .
Thanks a lot before.