iTurki
iTurki

Reputation: 16398

Can the Activity have a reference to the Service?

I know that Service can have a reference to Activity. Does the opposite hold ?

I have a service that monitor my Audio play/pause/stop . In my activity, I have 3 buttons for these functions and a seek bar also.

I want to call the appropriate function at the Service when the corresponding button is pressed at the Activty. Also I want the seekBar to set its max to the Audio length at the service. So, I figured that I need a reference to my service in order to do that.

Am I right or what?

Upvotes: 3

Views: 2802

Answers (1)

inazaruk
inazaruk

Reputation: 74790

Services should not hold references to activities, as this may result in memory leaks. An Activity can have a reference to a Service, this is called "Local Bound Services". A detailed explanation of what this is and how to implement and use it described in "Bound Services" article in Android's documentation.

Upvotes: 6

Related Questions