0

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);
Farido mastr
  • 353
  • 3
  • 10
  • reference https://stackoverflow.com/questions/6099364/how-to-use-pendingintent-to-communicate-from-a-service-to-a-client-activity – Jerson Sep 24 '20 at 10:51
  • @Jerson it's not what i'm searching for, i want to show current syncing progress not only when it finishes – Farido mastr Sep 24 '20 at 10:58
  • This makes no sense. If you want to bind to a `Service` then you need a client to bind. In this scenario what is the client that is binding to the `Service`? – David Wasser Sep 30 '20 at 13:09

0 Answers0