Reputation: 2085
From the android docs:
Although you usually implement either onBind() or onStartCommand(), it's sometimes necessary to implement both. For example, a music player might find it useful to allow its service to run indefinitely and also provide binding. This way, an activity can start the service to play some music and the music continues to play even if the user leaves the application. Then, when the user returns to the application, the activity can bind to the service to regain control of playback. source
In the service implementation i get from import android.app.Service
, onBind in abstract.[compileSdkVersion 28]
Am i missing something or is the documentation simply wrong with the Statement that i may implement onBind?
Upvotes: 1
Views: 1140
Reputation: 1084
If you check the documentation for onBind
, It says
Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl. Check Here
So Yes, You have to override onBind
.
As per your documentation ref given in the question,
Although you usually implement either onBind() or onStartCommand(), it's sometimes necessary to implement both.
So, This is not about overriding, This is about whether you have to provide actual implementation or not.
Upvotes: 4