我正在开发一个音乐应用,一切都很顺利,但最近程序会崩溃。当我在 Fabric 上查看崩溃列表时,发现这只会在 iOS 9 上发生。下面是引发崩溃的代码:
我无法重现此问题,因为它很少发生。上述代码会导致崩溃。Fatal Exception: java.lang.RuntimeException Unable to start activity ComponentInfo{android.store/android.store.MusicPlayerActivity}: java.lang.IllegalStateException: Not allowed to start service Intent { act=android.store.mediaservice.PLAY_PLAYLIST cmp=android.store/.mediaservice.MediaService (has extras) }: app is in background uid UidRecord{1aba0fa u0a192 SVC bg:+5m42s914ms idle change:uncached procs:1 seq(0,0,0)}
if (intent.hasExtra(MediaService.EXTRAS_INDEX)) {
Intent i = new Intent(getApplicationContext(), MediaService.class);
i.setAction(MediaService.ACTION_PLAY_PLAYLIST); i.putExtra(MediaService.EXTRAS_INDEX, intent.getIntExtra(MediaService.EXTRAS_INDEX, 0));
i.putExtra(MediaService.EXTRAS_TRACK_IDLIST, intent.getStringArrayExtra(MediaService.EXTRAS_TRACK_IDLIST)); startService(i);
} else if (intent.hasExtra(EXTRAS_SHUFFLE)) {
Intent i = new Intent(getApplicationContext(), MediaService.class);
i.setAction(MediaService.ACTION_PLAY_SHUFFLE);
i.putExtra(MediaService.EXTRAS_TRACK_IDLIST, intent.getStringArrayExtra(MediaService.EXTRAS_TRACK_IDLIST));
startService(i);
}
那么导致崩溃的主要原因是什么?有什么解决方案吗?