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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:29:46+00:00 2026-05-31T16:29:46+00:00

I have the service InfoReceiver . This service starts when the application starts and

  • 0

I have the service InfoReceiver. This service starts when the application starts and still be running when the application is closed.Also i have added the application to start on boot completed.The service will call the code i want every 82 milliseconds(24 hours). I don’t know how to make thread sleep while the phone is shutdown. Also i want to destroy completed the service after 120 hours.
here is my code

Thank you in advance!

InfoReceiver.java

 public class InfoReceiver extends Service {

        @Override
        public void onCreate()
        {
            super.onCreate();



                   //do something code


                }

                            }

MyBroadcastreceiver.java

public class MyBroadcastReceiver extends BroadcastReceiver {
private Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;
     Calendar cal = Calendar.getInstance();
     // add 5 minutes to the calendar object
     cal.add(Calendar.SECOND, 84000);
     Intent startServiceIntent = new Intent(context, InfoReceiver.class);
     PendingIntent startPIntent = PendingIntent.getBroadcast(context, 0, startServiceIntent, 0);
     AlarmManager am = (AlarmManager) mContext.getSystemService(mContext.ALARM_SERVICE); 
     am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), startPIntent);


}



}

Manifest file

<service android:name=".InfoReceiver"
        android:enabled="true">
        <intent-filter>
            <action android:name=".InfoReceiver"/>

        </intent-filter>
</service>
<receiver  android:process=":remote" android:name=".MyBroadcastReceiver">  
    <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" />  
    </intent-filter>  
</receiver>
  • 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-31T16:29:47+00:00Added an answer on May 31, 2026 at 4:29 pm

    You shouldn’t be using a thread sleep for this. The system will quickly kill off your service (in a relative sense of things, 24 hours is a long time to have the same app in memory). Instead you should be using an AlarmManager and request that your app has an intent fired so that you can do work every day. On boot, register the AlarmManager to do work every few days. Also, whenever you do a bit of work, save how long you’ve up (perhaps in a SharedPreferences), so you can know to stop requesting updates from the AlarmManager after that much time. This will get you a design where your app can go out of memory and die off — safely absolving you of any memory killing complaints — and then do work again when necessary.

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

Sidebar

Related Questions

My application starts with creating MyApplication extends Application I have service that runs on
I have service running in android to sync files when user wants. This is
Hi! I have a trouble with duplicating PendingIntents. My Application have Service that starts
I currently have service classes that look something like this public class UserService :
I have a service which is running in a system in several instances. I
I have service that will receive some data in 'json', i don't know which
I have a service called myService.svc. This service is exposed using a webHttpBinding binding.
I have service with thread, From activity I am calling start service(from Activity::onDestroy()) and
I have a service which runs every 1 minute through an alarm manager. This
In my Spring application I have service-layer methods marked as @Transactional(propagation=Propagation.REQUIRED) and am using

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.