Am creating music player.There is a service to stream music in background For the activity to service and from service to activity which mechanism, i should use ? Now i am using green robot EventBus and AIDL. In EventBus which one is better ? My app works fine, but issue is that simultaneous multiple click causing ANR in app.
recyclerViewAdapterTwo = new RecyclerViewAdapterTwo(ActivityTwo.this, trackList, categoriesList, new MusicTracksRecyclerViewAdapterTwo.ViewHolderOnClickHandler() {
@Override
public void onClick(int id, MusicTracksRecyclerViewAdapterTwo.VHItem vh) {
EventBus.getDefault().post(new PostSongListChangeToService(songDataList, position));
}
});
EventBus, Interface callback both are good options. Don't use Broadcast Receivers for this.
Now for the ANR, could you please share some code as where/how are you processing the events. Other then that try to pre-process most of the data in background thread and then jump to Main Thread only to actually play/pause/skip etc.
PS: If you are using Handler to actually preform things on the MainThread, try not to post everything in one go, give your queue some time between msg/runnables to run. It may add a slight delay on button click but will not freeze your Activity/Service.
you can refer to the Otto here : http://square.github.io/otto/