my app contains a list of dates in which there is toggle button
1.>on check it sets alarm and on uncheck it deletes the alarm
these is working normally but when i close aplication then alarm will automaically gets deleted so i want to save data in shared preferences when toggle button is clicked and delete particular data when btn is unchek from shared preferneces for this i am doing
SharedPreferences sharedPref = context.getSharedPreferences("com.example.dd.mydata", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("alarm"+cday+"_"+month,cday);
editor.commit();
where cday and month is alarm date and month
on recieve i have to fetch these data and match with date so that alarm can ring
so on recive i am doing this
SharedPreferences sharedPref = arg0.getSharedPreferences("com.example.dd.mydata", Context.MODE_PRIVATE);
String name = sharedPref.getString("alarm"+cday+"_"+cmonth, null);
in these way i am achiving the value of shared preferences in both class but it is working for single toggle button clicking more than 2 button **overrites the also tell me how can i check whether the current dates exists or not in shared prefernces
You can call SharedPreferences.contains(String key)
method.
For example, contains("alarm"+cday+"_"+cmonth)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.