I need to write an application that would work in the background, without a GUI, perform network requests to the server at intervals of 5 minutes, depending on the result, perform the notification. That is, we made a request, the melons are not valid (for example), we show notification. Is it possible, and if so, how?
1 answer
Create a service with START_STICKY and start it:
public class App extends Application { @Override public void onCreate() { super.onCreate(); startService(new Intent(this, YourService.class)); } } public class YourService extends Service { [...] @Override public int onStartCommand(Intent intent, int flags, int startId) { // do your jobs here return return START_STICKY; } } - Not! It is necessary that the application component itself, as the process always works in the background, regardless of whether the parent application that is running it (the service is the same for example) is running or not, like daemon's in linux. And this service, falls when we close the parent application. - Vladislav Aniskin
|