Stop the background service after particular time in android
Hi i need to stop the Background service which is already started after particular time.I will get the duration from server for when to stop the service.I have tried the Alarm Manager in android. Calendar cal = Calendar.getInstance(); Intent intent = new Intent(context, MyService.class); PendingIntent pintent = PendingIntent.getService(context, 0, intent, 0); AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); // Start every 30 seconds alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 60*1000, pintent); Log.e(TAG, "Service started in Activity");