Wednesday, 6 August 2014

എങ്ങനെ ആണ്ട്രോയിട് sharepreference ഉപയോഗിച്ച് data സ്റ്റോര്‍ ചെയ്യാം


ഞാന്‍ രണ്ടു function ഉസ് ചെയ്തു കാണിക്കാം
ഒന്നാമത്തെ functionil data സ്റ്റോര്‍ ചെയ്തും രണ്ടാമത്തെ functionil data retrieve ചെയ്യാം

int k=1;notificationCount=1;
SharedPreferences pref;

First function on button click
**********************************
public void getDataa(View v){
k++;

notificationCount++;
pref = getApplicationContext().getSharedPreferences("MyPrefmams", MODE_PRIVATE); 
Editor editor = pref.edit();
editor.putInt("notificationCountkey", notificationCount);
editor.commit(); 
   Log.d("getdata_c_k"," "+notificationCount+" "+k);
}


 Second function with button click
*************************************************
public void getDat(View v){
pref=getSharedPreferences("MyPrefmams",this.MODE_PRIVATE);
notificationCount =pref.getInt("notificationCountkey", 0);
   Log.d("getdata_c_k"," "+notificationCount+" "+k);
}

No comments:

Post a Comment