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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:04:26+00:00 2026-06-07T15:04:26+00:00

need a service that will run in background and it will awake after 30-120

  • 0

need a service that will run in background and it will awake after 30-120 seconds and find the location where the device is,then send the location to the data center and go to sleep.Again 30-120 seconds later service awake and determine location and go to sleep. I can start and stop the service manually.But i need to start(between 30 to 120 sec) and stop the service automatically.I can not remain the service live cause it will drain the battery.

So,My question is how can i start and stop the service automatically?

Thanks advance for any suggestion.

My code is

public class Service extends Activity {
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button start = (Button)findViewById(R.id.startButton);
        Button stop = (Button)findViewById(R.id.stopButton);

        start.setOnClickListener(startListener);
        stop.setOnClickListener(stopListener);

   }

private OnClickListener startListener = new OnClickListener() {
public void onClick(View v){
    startService(new Intent(Service.this,SimpleService.class));
}               

};

private OnClickListener stopListener = new OnClickListener() {
    public void onClick(View v){
        stopService(new Intent(Service.this,SimpleService.class));
    }               
};
}
  • 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-07T15:04:28+00:00Added an answer on June 7, 2026 at 3:04 pm

    You can user AlarmManager Class for your requirement. Create an alarm that will awake a Service on Specific Timer Interval ( in your case 30-120 seconds ). while awaking destroy the previous running service by calling it onDestroy() method.

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

Sidebar

Related Questions

I need to have ALWAYS a background service that will synchronize my Android application
I have a service that will send out notifications with timed tasks. I need
I need android service which will run in background and listen for urls from
I need an application that will run silently in the background, yet still interact
I need to make an app that will run forever at the background and
I am writing a Web app that will need to run a background process
I need to develop a service that will perform login through several login providers
I need to create a service that will be called back by a third
i need an sms service that can gives me a phone number and then
I need to daily run a script that will download a file from a

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.