admin管理员组

文章数量:1122999

I wrote an mp3 player app that I'd like to connect to Android Auto. I wrote the service and in the OnCreate method, I want to load my list of songs from my database so that when AA calls onLoadChildren, I can return the song info. The problem is, database accesses can't run on the main thread. I do the database access on another thread, and have it set the result ArrayList on the variable in the service when it's done, but by that time, AA has already called onLoadChildren and found no items.

I tried saving a list of track ids in shared preferences in the MP3 player app, but when I try to access them in the service, the track ids aren't in shared preferences. It looks like the shared preferences in the MP3 app aren't available in the service. The service is started by AA, not by my MP3 app, so I guess it can't access the MP3 player shared preferences.

I thought about trying to run the service in the background (so that the service could do the database access and wait for the result), but I don't see a way to do this, and I'm not sure AA would like that.

If there was a way to notify AA that the content has been updated (after it has called onGetRoot and onLoadChildren the first time) so that it could call them again, or refresh the content some how, that would be a solution but I don't see any way to do that in the AA documentation.

Apparently I have to have all my MP3 content instantly available.

本文标签: