Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 261
iTurki Avatar asked Dec 12 '25 23:12

iTurki


1 Answers

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.

like image 94
inazaruk Avatar answered Dec 14 '25 15:12

inazaruk