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

  • SEARCH
  • Home
  • 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 8258761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:39:21+00:00 2026-06-08T02:39:21+00:00

I need to do some recursive tasks, say do something after every five seconds.

  • 0

I need to do some recursive tasks, say do something after every five seconds. How to achieve that? I will need to do the recursive task in the background, so I think I can go with a Started Service.

PS. What I am actually trying to do is: taking picture using camera after every five seconds, from a background service.

I found following code in the developer-guide. The method below resides in a custom class which extends Handler class:

@Override
      public void handleMessage(Message msg) {
      // Do Something
      // HOW CAN i MAKE A RECURSIVE CALL (TO SOMEHOW CALL THIS FUNCTION) AFTER 5 SECONDS?
      // Stop the service using the startId
      stopSelf(msg.arg1);
      }
  }

Can I call something like Thread.sleep(5000) just before stopSelf()? (Not making sense to me…)

Or can I call something like this.sendMessageDelayed(msgOb, 5000); ?

Thanks.

  • 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-08T02:39:24+00:00Added an answer on June 8, 2026 at 2:39 am

    Ok then this is one way to do with a handler:

    int counter=0;
    private Handler mHandler = new Handler() {
            public void handleMessage(Message msg) {
                switch (msg.what) {
                case MSG_TAKE_PIC:
                    if(counter==5) {
                        mHandler.removeMessages(MSG_UPDATE_CALLTIME);
                        break;
                    }
                    else {
                        //take pic here and then
                        counter++;
                        sendEmptyMessageDelayed(MSG_TAKE_PIC, 5000);
                    }
    
                }
            }
        };
    

    and where you want to start taking the pic just:

    mHandler.sendEmptyMessageDelayed(MSG_TAKE_PIC, 5000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write an application that will check for something every X time
I need some help on the SimpleXML calls for a recursive function that lists
I have some sort of recursive function, but I need to parse a string,
I need some assistance in Qt on Windows 7. It seems that Qt readyRead()
I need to write a query that calls a recursive query many times. I
I have a multi-thread C# application that uses some recursive functions in a dll.
I have a simple html structure that I need to traverse. For some reason
I use ScheduledExecutorService to schedule some tasks which need to run periodically. I want
I need some help to understand analysing recursive algorithms. I quickly made this algorithm
Need some regular expressions help. So far I have my code working to allow

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.