Android - start alarm service immediately?

前端 未结 2 1455
深忆病人
深忆病人 2021-01-26 07:31

I have created an On Boot Receiver to repeatedly call a wakeful intent service every 5 minutes but cannot figure out how to start the service immediately when the app is install

相关标签:
2条回答
  • 2021-01-26 07:49

    If you want to set an alarmmanager to start your service when the app is installed, then it's not possible. It's a OS limitation, security if you will. But if you want to start the service in the moment the app starts, just call it, it will keep runing.

    0 讨论(0)
  • 2021-01-26 08:08

    Essentially, since the Application object is created when the application is started and when the BOOT_COMPLETED Intent is received, you could register with the AlarmManager in the onCreate method in your custom Application class. Just be aware that the Application object is instantiated every time the process starts, which includes cases where the process is temporarily killed to save resources. But if you don't change the PendingIntent in any way, it should be no problem to register over and over again.

    However, it is not possible to start the application when it is installed, there has to be some user interaction first.

    0 讨论(0)
提交回复
热议问题