我已经实现了媒体播放器控制器。问题是,从用户控件可见的媒体播放器活动转移到之前的活动时,会发生Window泄漏错误。此外,在添加媒体控制器时,后退按钮也会变为禁用。此错误发生在bestAudioController.show()的第70行;
public void playAudio() {
bestService.playSong();
bestAudioController.show();
}
这行playAudio()
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder
iBinder) {
Log.e("onServiceConnected,","MAINACTIVITY");
bestService = ((BestService.MyBinder) iBinder).getService();
isBound = true;
LocalBroadcastManager.getInstance(getApplicationContext()).
registerReceiver(onPrepareReceiver,
new IntentFilter("MEDIA_PLAYER_PREPARED"));
playAudio();
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Log.e("onServiceDisconnected","MAINACTIVITY");
isBound = false;
}
};
错误日志显示以下内容
Activity com.example.hawk.hojaa.PlayerActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView{52a3f974 V.E.....
R.....ID 0,0-768,176} that was originally added here
android.view.WindowLeaked: Activity com.example.hawk.hojaa.PlayerActivity
has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView{52a3f974 V.E.....
R.....ID 0,0-768,176} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
at
android.view.WindowManagerGlobal.
addView(WindowManagerGlobal.java:239)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.widget.MediaController.show(MediaController.java:346)
at android.widget.MediaController.show(MediaController.java:306)
at com.example.hawk.aise.PlayerActivity.
playAudio(PlayerActivity.java:84)
at com.example.hawk.aise.
PlayerActivity$1.onServiceConnected(PlayerActivity.java:70)
at android.app.
LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1106)
at android.app.
LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1123)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.
run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
我用来解决此问题的解决方案是在dismiss()
之前的对话框上调用hide()
,以确保在转到其他活动之前完全删除对话框。
...
progressDialog.dismiss();
progressDialog.hide();
...