First of all, I think that you will call the Service class from the Activity class or from any BroadCastReceiver class.
You want to start the service after a certain or after 5000ms. Although your question is not clear to me. However, to my knowledge, you should call a service from your class of service. For instance:
public class UpdateWidgetServiceDemo extends Service { public static int numberOfItems=0; String resultURL="";
The important part is important here:
Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 10); Intent intent1 = new Intent(this, UpdateWidgetServiceDemo.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent1, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); int i; i=15; alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), i* 1000, pintent);
I think your problem will be solved.
Enjoy !!!
source share