Running code the first time you run an Android application

I have a new application for android earthquake notification, which presents the original version. I am currently having a problem. My application has a service running in the background, this is a schedule for starting each period of X. In order to plan itself, it must be launched at least once. This currently happens when the phone boots up. Obviously, I do not want the user to restart his phone as soon as he has installed the application.

Also, I do not want my application user interface to call it every time it starts. Because it clearly spoils the user's planning. Instead, I need to know that when the UI application launches for the first time on the phone, it must be able to start the service so that it can plan itself and continue to work as expected in the future.

An alternative way that I could decide is that if I know the list of existing alarms in order to wake up the service, since then I will find out if the application is already running or not.

If you want to see the source code of an application or run a binary file; Take a look at the following github url

I hope I'm clear in my intentions. Just to give some idea about the application; This is a notification application for your Android phone, which generates a notification when an earthquake occurs, and also shows the affected area on the map with additional functionality. It has a UI app that shows a list of earthquakes in the past. And a service that keeps track of new ones.

Thanks in advance.

+3
source share
2 answers

I am not at home, so this will be brief until I can edit to fill out.

First, I think you can configure BroadcastReceiver to notify you of a package installation for initial setup.

, , PendingIntent FLAG_NO_CREATE. , , , , .

+2

, startService() : , startService(), , ( ); , .

onStart (Intent, int), , .

: isScheduled, , .

, , , , Application, , . onStart .

+1

Source: https://habr.com/ru/post/1759768/


All Articles