2

I followed the demo app in the ACRCloud Android sdk. All the code for music recognition was in the activity.

I did the same but in a service. So can we initialize the ACRCloudClient in the service?(ACRCloudClient extends from Activity).

How can we then do it in the service if we can't.

I have the implementation code in the service in another question. Here is the link See this question

Cœur
  • 37,241
  • 25
  • 195
  • 267
nick.tdr
  • 4,627
  • 4
  • 28
  • 41

2 Answers2

0

SDK can work in a service, but because SDK needs recording, it may be interrupted during execution in the background.Can your implementation code work now? You can set "this.mConfig.context = null", and ignore that null exception.

Pony
  • 1
  • 1
0

I checked the implementation of the ACRCloudClient and its extends android Activity. Also ACRCloudClient uses shared preferences(that's why I am getting a null pointer exception).

Since keeping a reference to an activity in a service is not a good Idea its best to Implement the above code in the activity. All the implementation of recognizing is being done in a separate thread anyway in the ACRCloudClient class so there is no point of creating another service for that.

I answered the same in another question as well link to related question

nick.tdr
  • 4,627
  • 4
  • 28
  • 41