问题
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
}
}
回答1:
use Timer()
and TimerTask()
:
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//run your service
}
}, 60000);
回答2:
When you receive the BOOT_COMPLETED intent you should use the AlarmManager to setup an pending intent that will fire after 60 seconds.
来源:https://stackoverflow.com/questions/4562269/android-app-how-to-delay-your-service-start-on-phone-boot