How To Set Multiple Reminders In Android
Solution 1:
If I understand correctly, your approach using an activity only allows you to add one event at a time because the user has to interact with the device to confirm it. What you want is the new CalendarContract
introduced in 4.0.
From Android Cookbook:
The ContentProvider-based method may be preferable if you do not want the user to have to interact with a calendaring application. In Froyo and Gingerbread and Honeycomb releases, you had to "know" the names to use for the various fields you wanted to interact with. We do not cover this method as it is officially unsupported, but you can find a good article on the web by our contributor Jim Blacker, at http://jimblackler.net/blog/?p=151.
Effective with Ice Cream Sandwich (Android 4, API level 14), the new CalendarContract class holds, in a variety of nested classes, all the constants needed to make a portable calendar application. This is shown inserting a Calendar Event directly into the user's first Calendar (using id 1); obviously there should be a drop-down listing the user's calendars in a real application.
publicvoidaddEvent(Context ctx, String title, Calendar start, Calendar end) {
Log.d(TAG, "AddUsingContentProvider.addEvent()");
TextViewcalendarList=
(TextView) ((Activity) ctx).findViewById(R.id.calendarList);
ContentResolvercontentResolver= ctx.getContentResolver();
ContentValuescalEvent=newContentValues();
calEvent.put(CalendarContract.Events.CALENDAR_ID, 1); // XXX pick)
calEvent.put(CalendarContract.Events.TITLE, title);
calEvent.put(CalendarContract.Events.DTSTART, start.getTimeInMillis());
calEvent.put(CalendarContract.Events.DTEND, end.getTimeInMillis());
calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "Canada/Eastern");
Uriuri= contentResolver.insert(CalendarContract.Events.CONTENT_URI, calEvent);
// The returned Uri contains the content-retriever URI for // the newly-inserted event, including its idintid= Integer.parseInt(uri.getLastPathSegment());
Toast.makeText(ctx, "Created Calendar Event " + id,
Toast.LENGTH_SHORT).show();
}
Solution 2:
I think what you're looking for is AlarmManager
.
Post a Comment for "How To Set Multiple Reminders In Android"