Answer the question
In order to leave comments, you need to log in
Is it possible to use one Service for different tasks?
I update the widget with Service every 24 hours.
Such a thing is that it is necessary to do one more action (namely, notifications [notification]) once every 24 hours, but with a different reference point. Those. the widget is updated at 00:01, and the notification, for example, should appear at 17:40.
At the moment I am implementing through two services, which is not very beautiful and dreary in itself. Especially because the data for Notification is in the first service, so I call the first service, and from it the second one. It turns out not at all a beautiful software centipede.
Is it possible to somehow make one Service work for these two tasks, or is there nothing better than what we have now? :)
Answer the question
In order to leave comments, you need to log in
You can use pendingIntent with different requestCode. For example:
public static void startProgramNotifications(Context c) {
AlarmManager am;
am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(c, TimerReceiver.class); //TimerReceiver - сервис
PendingIntent pendingIntent = PendingIntent.getBroadcast(c, 0, // 0 - requestCode
intent, PendingIntent.FLAG_CANCEL_CURRENT );
am.cancel(pendingIntent); //cancel active intent, optional
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ setNitifTime(), pendingIntent);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question