My objective is to sync data using AlarmManager with bound foreground service to show a progress dialog when the application is opened otherwise it shows a notification
I did it without alarm manager it works fine, But i don't know how to bound service using the pendingintent as shown below
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
manualSyncServiceListener = new OManualSyncService.OManualSyncServiceListener();
syncingServiceIntent = new Intent(this, OManualSyncService.class);
if(bound){
oManualSyncService.setListener(null); // unregister
unbindService(serviceConnection);
bound = false;
}
long frequency = 15000;
PendingIntent pendingIntent = PendingIntent.getService(this, REQUEST_AUTOMATIC_SYNC, syncingServiceIntent, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + frequency, pendingIntent);
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, frequency, pendingIntent);
}
else {
alarmManager.set(AlarmManager.RTC_WAKEUP, frequency, pendingIntent);
}
I need something like this
bindService(pendingIntent, serviceConnection, Context.BIND_AUTO_CREATE);