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 9201421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:00:15+00:00 2026-06-17T23:00:15+00:00

In my application I have created a calendar with Gridview and in that Gridview

  • 0

In my application I have created a calendar with Gridview and in that Gridview I am displaying dates and some availability of events with the help of Imageview and to do this I have created a handler.

Now I want to stop the handler.

MainActivity.java

// inside oncreate

Handler handler = new Handler();
refreshCalendar();

// outside oncreate

public void refreshCalendar() { 
    calAdapter.refreshDays();
    calAdapter.notifyDataSetChanged();
    handler.post(calendarUpdater);
    calTitle.setText(android.text.format.DateFormat.format("MMMM yyyy", cal));
}
public Runnable calendarUpdater = new Runnable() {

    @Override
    public void run() {
        items.clear();
        allData = new ArrayList<HashMap<String,String>>();
        allData.clear();
        allData = db.showAllEvents();

        String currentDate = (String)android.text.format.DateFormat.format("MM/yyyy", cal);
        for(int i=0; i<allData.size(); i++)
        {
            String date[] = allData.get(i).get("date").split("/");
            String md[] = currentDate.split("/");
            if(date[1].equals(md[0]) && date[2].equals(md[1]))
            {
                items.add(date[0]);
                System.out.println("dates: "+date[0]);
            }
        }
        calAdapter.setItems(items);
        calAdapter.notifyDataSetChanged();
    }
};

Please tell me how and where I should disable this thread.

  • 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-06-17T23:00:17+00:00Added an answer on June 17, 2026 at 11:00 pm

    You can use this to stop that runnable

    handler.removeCallbacks(calendarUpdater);
    

    removeCallbacks(Runnable r) :Remove any pending posts of Runnable r that are in the message queue.

    Edit

    You can organize your code like this

    In your onCreate() of MainActivity.java

    Handler handler = new Handler();
    refreshCalendar()
    
    //outside  oncreate 
    
    public void refreshCalendar() { 
        calAdapter.refreshDays();
        calAdapter.notifyDataSetChanged();
        startRepeatingTask();
        calTitle.setText(android.text.format.DateFormat.format("MMMM yyyy", cal));
    }
    
    public Runnable calendarUpdater = new Runnable() {
    
        @Override
        public void run() {
            items.clear();
            allData = new ArrayList<HashMap<String,String>>();
            allData.clear();
            allData = db.showAllEvents();
    
            String currentDate = (String)android.text.format.DateFormat.format("MM/yyyy", cal);
            for(int i=0; i<allData.size(); i++)
            {
                String date[] = allData.get(i).get("date").split("/");
                String md[] = currentDate.split("/");
                if(date[1].equals(md[0]) && date[2].equals(md[1]))
                {
                    items.add(date[0]);
                    System.out.println("dates: "+date[0]);
                }
            }
            calAdapter.setItems(items);
            calAdapter.notifyDataSetChanged();
            handler.postDelayed(calendarUpdater,5000); // 5 seconds
        }
    };
    
    void startRepeatingTask()
    {
        calendarUpdater.run(); 
    }
    
    void stopRepeatingTask()
    {
        handler.removeCallbacks(calendarUpdater);
    }
    

    Now you can just call startRepeatingTask() to posting message and to stop use stopRepeatingTask()

    Inherited from following link

    Repeat a task with a time delay?

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

Sidebar

Related Questions

I have created a play application and have some models. One of them contains
I have created Windows Application. In this, I have multiple tables in dataset, now
I have created an application that connect on a web-server and reads an xml
I have a Grails application I created a Gregorian Calendar GMT date. The time
I have a calendar application, and in that calendar application, there is a mini
I am developing a calendar application,where i have created a recurring event n native
Currently I am working on Calendar Application for iPhone. In this project i have
I have an ASP.NET MVC application that is calendar-like. As per the NerdDinner example,
I have created a web application in that application i have added two folder.
I have an application that gets information from google calendar by getting them from

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.