Erik
Erik

Reputation: 5119

Android app How to delay your Service start on phone boot

hi When my app get the ACTION_BOOT_COMPLETED it starts a service. I would like to delay that for lets say 60sec. Can i do that in the:

public class StartAtBootServiceReceiver extends BroadcastReceiver 
{

        public void onReceive(Context context, Intent intent) 
        {
           // Delay...60sec
        }
}

Upvotes: 5

Views: 4423

Answers (2)

Prashast
Prashast

Reputation: 5675

When you receive the BOOT_COMPLETED intent you should use the AlarmManager to setup an pending intent that will fire after 60 seconds.

Upvotes: 2

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43098

use Timer() and TimerTask():

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                //run your service
            }
        }, 60000);

Upvotes: 4

Related Questions