This is my code but this calls my activity instead of a function i want ,this code runs under a function that is inturn made in a Service:
Intent intent = new Intent(this, abc.class);
PendingIntent pi = PendingIntent.getService(Server.this, 0, intent, 0);
AlarmManager almmgr = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar cldr = Calendar.getInstance();
int min1 = cldr.get(Calendar.MINUTE);
cldr.setTimeInMillis(System.currentTimeMillis());
cldr.add(Calendar.SECOND, 30);
almmgr.set(AlarmManager.RTC_WAKEUP, cldr.getTimeInMillis(), pi);
basically I would like to take inputs from 2 timepickers and when the difference of times between these 2 is achieved then call a function which does some control stuff!
You don’t, at least not directly.
You can create a service, and you can use a
getService()PendingIntentin order to haveAlarmManagerinvoke that service. However, you will get control inonStartCommand(), not some other “specific function in the service itself”. You are welcome to call some other “specific function in the service itself” fromonStartCommand()if you wish, but please bear in mind that you are on the main application thread and therefore cannot do very much. If you have a lot of work to do, you might consider creating anIntentServiceinstead of a plainService, so that you can get control on a background thread (inonHandleIntent()).