Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6603209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:58:42+00:00 2026-05-25T18:58:42+00:00

Possible Duplicate: android calendar delete event Actually i write a code for inserting and

  • 0

Possible Duplicate:
android calendar delete event

Actually i write a code for inserting and deleting event from the calendar.The code i have written does the following jobs.

  1. Before inserting new event in the device calendar it will delete all the event from the device calendar that are put by my app and insert new event in the calendar.So the code first include deleting of all event from the calendar that are put by my app and insert new event.All works fine but sometime it cant delete all the event from the calendar and this happen sometime only and as a result duplicate element insert in my device calendar.So why these happen can anyone please suggest me..i have send my code..

    public void setAlertOnDevice(Context c)
    {                   
    Resources res = c.getResources();
    
    Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events");
    
    Uri REMINDERS_URI = Uri.parse("content://com.android.calendar/" + "reminders");
    
    ContentResolver cr = c.getContentResolver();
    
    //Delete calendar event
    while(m_calendarEventCount > 0)
    {
        cr.delete(m_calendarEvents[m_calendarEventCount - 1], null, null);
        m_calendarEventCount = m_calendarEventCount - 1;            
    }
    
    //set Alerts in device calendar
    Date dtStartDate = getStartDate();                  
    boolean bDeleteAndReturn = false;   
    
    Calendar cal = Calendar.getInstance();
    
    if (dtStartDate.getTime() ==  getDefaultDate().getTime())
    {
        bDeleteAndReturn = true;
        dtStartDate = cal.getTime();
    }  
    
    getOffsetsForCycleStages(m_iAvgCycleTime);
    
    if(!m_bNextCycleAlert && !m_bSafeAlert && !m_bUnsafeAlert && !m_bFertileAlert && !m_bPMSAlert)
        m_reminderText = "LoveCycles";
    
    if(bDeleteAndReturn == false)
    {
        if (m_bNextCycleAlert && m_iStart > 0)
        {
            cal.setTime(dtStartDate);
            cal.add(Calendar.DATE, m_iStart);
    
            String str = m_reminderText + res.getString(R.string.alert_start);                                          
            m_strDescription = res.getString(R.string.alert_start_msg);
    
            ContentValues values = new ContentValues();
            values.put("calendar_id", 1);
            values.put("title", str);
            values.put("description", m_strDescription);                    
            values.put("dtstart", cal.getTimeInMillis()); 
            values.put("dtend", cal.getTimeInMillis()); 
            values.put("hasAlarm", 1);
            Uri event = cr.insert(EVENTS_URI, values);
    
            m_calendarEvents[m_calendarEventCount] = event;
            m_calendarEventCount = m_calendarEventCount + 1;
    
            values = new ContentValues();
            values.put("event_id", Long.parseLong(event.getLastPathSegment()));
            values.put("method", 1);
            values.put("minutes", 10);
            cr.insert(REMINDERS_URI, values);
        }
        if (m_bSafeAlert)
        {
            if (m_iSafe1 > 0)
            {
                cal.setTime(dtStartDate);
                cal.add(Calendar.DATE, m_iSafe1);
    
                String str = m_reminderText + res.getString(R.string.alert_safe);                 
                m_strDescription = res.getString(R.string.alert_safe_msg) + " " + new Integer(m_iUnsafe1-m_iSafe1-1);
    
                ContentValues values = new ContentValues();
                values.put("calendar_id", 1);
                values.put("title", str);
                values.put("description", m_strDescription);
                values.put("dtstart", cal.getTimeInMillis()); 
                values.put("dtend", cal.getTimeInMillis()); 
                values.put("hasAlarm", 1);
                Uri event = cr.insert(EVENTS_URI, values);
    
                m_calendarEvents[m_calendarEventCount] = event;
                m_calendarEventCount = m_calendarEventCount + 1;
    
                values = new ContentValues();
                values.put("event_id", Long.parseLong(event.getLastPathSegment()));
                values.put("method", 1);
                values.put("minutes", 10);
                cr.insert(REMINDERS_URI, values);
            }
            if (m_iSafe2 > 0)
            {
                cal.setTime(dtStartDate);
                cal.add(Calendar.DATE, m_iSafe2);
    
                String str = m_reminderText + res.getString(R.string.alert_safe);                      
                m_strDescription = res.getString(R.string.alert_safe_msg) + " " + new Integer(CycleManager.getSingletonObject().m_iAvgCycleTime-m_iSafe2-1);
    
                ContentValues values = new ContentValues();
                values.put("calendar_id", 1);
                values.put("title", str);
                values.put("description", m_strDescription);
                values.put("dtstart", cal.getTimeInMillis()); 
                values.put("dtend", cal.getTimeInMillis()); 
                values.put("hasAlarm", 1);
                Uri event = cr.insert(EVENTS_URI, values);
    
                m_calendarEvents[m_calendarEventCount] = event;
                m_calendarEventCount = m_calendarEventCount + 1;
    
                values = new ContentValues();
                values.put("event_id", Long.parseLong(event.getLastPathSegment()));
                values.put("method", 1);
                values.put("minutes", 10);
                cr.insert(REMINDERS_URI, values);   
            }
        }
        if (m_bUnsafeAlert)
        {
            if (m_iUnsafe1 > 0)
            {
                cal.setTime(dtStartDate);
                cal.add(Calendar.DATE, m_iUnsafe1); 
    
                String str = m_reminderText + res.getString(R.string.alert_unsafe);
                m_strDescription = res.getString(R.string.alert_unsafe_msg) + " " + new Integer(m_iFertile-m_iUnsafe1-1);
    
                ContentValues values = new ContentValues();
                values.put("calendar_id", 1);
                values.put("title", str);
                values.put("description", m_strDescription);
                values.put("dtstart", cal.getTimeInMillis()); 
                values.put("dtend", cal.getTimeInMillis()); 
                values.put("hasAlarm", 1);
                Uri event = cr.insert(EVENTS_URI, values);
    
                m_calendarEvents[m_calendarEventCount] = event;
                m_calendarEventCount = m_calendarEventCount + 1;
    
                values = new ContentValues();
                values.put("event_id", Long.parseLong(event.getLastPathSegment()));
                values.put("method", 1);
                values.put("minutes", 10);
                cr.insert(REMINDERS_URI, values);
            }
            if (m_iUnsafe2 > 0)
            {
                cal.setTime(dtStartDate);
                cal.add(Calendar.DATE, m_iUnsafe2);
    
                String str = m_reminderText + res.getString(R.string.alert_unsafe);                  
                m_strDescription = res.getString(R.string.alert_unsafe_msg) + " " + new Integer(m_iSafe2-m_iUnsafe2-1);
    
                ContentValues values = new ContentValues();
                values.put("calendar_id", 1);
                values.put("title", str);
                values.put("description", m_strDescription);
                values.put("dtstart", cal.getTimeInMillis()); 
                values.put("dtend", cal.getTimeInMillis()); 
                values.put("hasAlarm", 1);
                Uri event = cr.insert(EVENTS_URI, values);
    
                m_calendarEvents[m_calendarEventCount] = event;
                m_calendarEventCount = m_calendarEventCount + 1;
    
                values = new ContentValues();
                values.put("event_id", Long.parseLong(event.getLastPathSegment()));
                values.put("method", 1);
                values.put("minutes", 10);
                cr.insert(REMINDERS_URI, values);
            }
        }
        if (m_bFertileAlert && m_iFertile > 0)
        {
            cal.setTime(dtStartDate);
            cal.add(Calendar.DATE, m_iFertile); 
    
            String str=m_reminderText + res.getString(R.string.alert_fertile);          
            m_strDescription = res.getString(R.string.alert_fertile_msg) + " " + new Integer(m_iUnsafe2-m_iFertile-1);
    
            ContentValues values = new ContentValues();
            values.put("calendar_id", 1);
            values.put("title", str);
            values.put("description", m_strDescription);
            values.put("dtstart", cal.getTimeInMillis()); 
            values.put("dtend", cal.getTimeInMillis()); 
            values.put("hasAlarm", 1);
            Uri event = cr.insert(EVENTS_URI, values);
    
            m_calendarEvents[m_calendarEventCount] = event;
            m_calendarEventCount = m_calendarEventCount + 1;
    
            values = new ContentValues();
            values.put("event_id", Long.parseLong(event.getLastPathSegment()));
            values.put("method", 1);
            values.put("minutes", 10);
            cr.insert(REMINDERS_URI, values);
        }
        if (m_bPMSAlert)
        {
            cal.setTime(dtStartDate);
            cal.add(Calendar.DATE, m_iStart - 7);
    
            String str = m_reminderText + res.getString(R.string.alert_pms);               
            m_strDescription = res.getString(R.string.alert_pms_msg);
    
            ContentValues values = new ContentValues();
            values.put("calendar_id", 1);
            values.put("title", str);
            values.put("description", m_strDescription);
            values.put("dtstart", cal.getTimeInMillis()); 
            values.put("dtend", cal.getTimeInMillis()); 
            values.put("hasAlarm", 1);
            Uri event = cr.insert(EVENTS_URI, values);
    
            m_calendarEvents[m_calendarEventCount] = event;
            m_calendarEventCount = m_calendarEventCount + 1;
    
            values = new ContentValues();
            values.put("event_id", Long.parseLong(event.getLastPathSegment()));
            values.put("method", 1);
            values.put("minutes", 10);
            cr.insert( REMINDERS_URI, values);
        }
    }}
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:58:42+00:00Added an answer on May 25, 2026 at 6:58 pm

    This post may help you.Here is GData to help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Developing for Android in Eclipse: R.java not generating I have imported a
Possible Duplicate: Can we delete an SMS in Android before it reaches the inbox?
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: Android: How to resize a custom view programmatically? What's the best way
Possible Duplicate: Android - shadow on text? How can i make shadow effect text
Possible Duplicate: NoClassDefFoundError - Eclipse and Android I'm seeing this question is getting asked
Possible Duplicate: How to test the performance of an Android application? How can i
Possible Duplicate: How to test the performance of an Android application? The test cases

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.