-1

Any idea regarding update seekbar progress from service in android. i was trying but cant update progress of seekbar.

please help me out.

thank you in advance.

2 Answers2

1

I have a simple idea to do this if you want

  1. in your Service update your seek bar value and put it in to Shared preferences.
  2. In your Activity or Fragment use a handler to get this update value from shared preferences.
  3. Update your seek bar for this value.
  4. Remove your handler if your task is done
Jeetu
  • 686
  • 2
  • 10
  • 20
  • Thank you, one more question i was ask is .. How can i get onComplition() event of MediaPlayer from service in Fragment or Activity ? – Brijesh Chavda Sep 10 '15 at 03:53
  • Same thing you can try to do this change a status values of your shared preferences in your onComplete() method. – Jeetu Sep 11 '15 at 07:30
0

Using a Messenger is another simple way to communicate between a Service and an Activity.

In the Activity, create a Handler with a corresponding Messenger. This will handle messages from your Service.

class ResponseHandler extends Handler {
@Override public void handleMessage(Message message) {
        Toast.makeText(this, "message from service",
                Toast.LENGTH_SHORT).show();
}

}

Messenger messenger = new Messenger(new ResponseHandler());

The Messenger can be passed to the service by attaching it to a Message:

Message message = Message.obtain(null, MyService.ADD_RESPONSE_HANDLER);
message.replyTo = messenger;
try {
myService.send(message);
catch (RemoteException e) {
e.printStackTrace();
}

A full example can be found in the API demos: MessengerService and MessengerServiceActivity link. Refer to the full example for how MyService works.

Cheerag
  • 415
  • 3
  • 10