由于某些原因,当我完成指定的活动时,我的Activity崩溃了。之前当我只有onDestroy时,一切正常,除非我最小化应用程序(HOME按钮),音乐仍在播放。
根据我收集的内容,我最终使用onDestroy()
,onResume()
和onPause()
来操纵MediaPlayer
...但由于某种原因,当活动结束时,一个警告对话框,说明Unforunately, ProgramX has stopped.
尽管如此,它仍然继续下一个startActivity(intent)。
MediaPlayerAssets gls; // custom MediaPlayer Assets to fetch MediaPlayer objects
@Override
protected void onPause()
{
super.onPause();
gls.glbgm.pause(); // my logCat demands that the error occurs here.
resumeToPosition = gls.glbgm.getCurrentPosition();
}
@Override
protected void onRestart()
{
super.onRestart();
if(gls.glbgm != null && !gls.glbgm.isPlaying())
{
gls.glbgm.seekTo(resumeToPosition);
gls.glbgm.start();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
gls.glbgm.release();
gls.score.release();
gls.loser.release();
}
E / AndroidRuntime(23422):致命异常:主要
E / AndroidRuntime(23422):java.lang.RuntimeException:无法暂停活动
{com.fenrirAB.request / getluckyPkg.GetLuckyGame}:java.lang.IllegalStateException
E / AndroidRuntime(23422):在android.app.ActivityThread.performPauseActivity(ActivityThread.java:3112)
E / AndroidRuntime(23422):在android.app.ActivityThread.performPauseActivity(ActivityThread.java:3067)
E / AndroidRuntime(23422):在android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3045)
E / AndroidRuntime(23422):在android.app.ActivityThread.access $ 900(ActivityThread.java:152)
E / AndroidRuntime(23422):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1295)
E / AndroidRuntime(23422):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(23422):在android.os.Looper.loop(Looper.java:137)
E / AndroidRuntime(23422):在android.app.ActivityThread.main(ActivityThread.java:5299)
E / AndroidRuntime(23422):at java.lang.reflect.Method.invokeNative(Native Method)
E / AndroidRuntime(23422):at java.lang.reflect.Method.invoke(Method.java:511)
E / AndroidRuntime(23422):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1102)
E / AndroidRuntime(23422):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
E / AndroidRuntime(23422):at dalvik.system.NativeStart.main(Native Method)
E / AndroidRuntime(23422):引起:java.lang.IllegalStateException
E / AndroidRuntime(23422):在android.media.MediaPlayer._pause(Native Method)
E / AndroidRuntime(23422):在android.media.MediaPlayer.pause(MediaPlayer.java:1372)
E / AndroidRuntime(23422):at getluckyPkg.GetLuckyGame.onPause(GetLuckyGame.java:357)
E / AndroidRuntime(23422):在android.app.Activity.performPause(Activity.java:5447)
E / AndroidRuntime(23422):在android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1243)
E / AndroidRuntime(23422):在android.app.ActivityThread.performPauseActivity(ActivityThread.java:3098)
E / AndroidRuntime(23422):...还有12个