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 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 have downloaded the Gdata objective c client application from GoogleCode but when I
I'm an Objective-C developer porting an application to the .Net world. In my Obj-C
I am currently working on an iPhone 2.1 application. I am new to Objective
Application able to record error in OnError, but we are not able to do
The application my team is currently developing has a DLL that is used to
i'm writing an application in objective-c (using cocoa). i have a PDF template, i
After four weeks of learning Objective-C for the iPhone, my first useful application is
I'm writing an application for the iPhone that communicates with a SQLite database but
I want to create an objective c application that interprets a list of .aiml
I am developping an objective c application and I would like to detect non

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.