Android - start alarm service immediately?

前端 未结 2 1456
深忆病人
深忆病人 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 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.

提交回复
热议问题