I have created one service which I want to call periodically through AlarmManager. I have written code for same, But it's not calling. If I call BroadcasrReciever through AlarmManager, then it's working fine.
Below is my Code,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Intent alarmIntent = new Intent(this, LocationUpdateService1.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
manager.setRepeating(AlarmManager.RTC_WAKEUP, 20000, 11000, pendingIntent);
}
My service class is,
public class LocationUpdateService1 extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
Toast.makeText(getApplicationContext(), "I created", Toast.LENGTH_LONG);
return null;
}
}
My manifiest file,
<service
android:name=".Services.LocationUpdateService1">
</service>
Do I have to create BroadcastReceiver class to call my service ? What is wrong in my code ? and why it's not calling periodically ?