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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:02:09+00:00 2026-05-19T01:02:09+00:00

my application objective is to save location updates every ,let say, 20 minuets .

  • 0

my application objective is to save location updates every ,let say, 20 minuets .

I used service and it worked fine , but when i lock the screen or it is locked automatically the service stop running .
when i unlock it , service runs again.

highlight on my code:

Service()

onCreat(){
   call timer();
 }

timer(){
   code
 }

How to make my code run all the time in all conditions?

  • 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-19T01:02:10+00:00Added an answer on May 19, 2026 at 1:02 am

    Yes, use AlarmManager to start the service every 10 minutes for example with setRepeating like below. Get rid of timer in service and just let service run task in oncreate or onCommand start to completion.

        int SECS = 1000;
        int MINS = 60 * SECS;
        Calendar cal = Calendar.getInstance();
        Intent in = new Intent(context, YourService.class);
        PendingIntent pi = PendingIntent.getService(context, 0, in, PendingIntent.FLAG_UPDATE_CURRENT);
    
        AlarmManager alarms = (AlarmManager)context.getSystemService(
                Context.ALARM_SERVICE);
        alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 
                10 * MINS, pi);
    

    You can create an activity to contain this code in an onclick handler from a button to start the service. If you want to run at boot time you need to put this in a broadcast receiver that gets notified when device is up, but that is another topic on its own.

    The reason service and timer does not work when device is asleep is because cpu is off and your code has no wake lock. AlarmManager will wake up the cpu ever so slightly to run your service.

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

Sidebar

Related Questions

I am writing a simple console application in Objective-C but I have heard that
I have this iPhone application that let users take a picture and save it
I'm trying to make my first application using Objective C + Core Data, but
I am writing an application in Objective-C whose functionality is to call and execute
I'm making a console-based application in Objective-C which relies on being able to clear
I have an objective-c application for OS X that compares two sqlite DB's and
I'm an Objective-C developer porting an application to the .Net world. In my Obj-C
In objective C, I'm trying to resize an application window after a button is
I'm new to objective-c and at the moment developing a small application. I have
I am writing a string tokenizer in Objective-C for an iPhone application . I

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.