Android:应用程序在关闭并重新打开后崩溃

时间:2017-05-07 11:59:41

标签: android android-mediaplayer

当用户关闭应用程序然后再次尝试打开它时,应用程序崩溃。由于某种原因,这门课会引起麻烦:

05-07 13:56:06.726 31550-31550/com.app.hudhud.myapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: com.app.hudhud.myapp, PID: 31550
                                                                  java.lang.RuntimeException: Unable to resume activity {com.app.hudhud.myapp/com.app.hudhud.myapp.Bon}: java.lang.IllegalStateException
                                                                      at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4156)
                                                                      at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4250)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:158)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:7229)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                   Caused by: java.lang.IllegalStateException
                                                                      at android.media.MediaPlayer._start(Native Method)
                                                                      at android.media.MediaPlayer.start(MediaPlayer.java:1425)
                                                                      at com.app.hudhud.myapp.PageFragment_Bon.onResume(PageFragment_Bon.java:148)
                                                                      at android.support.v4.app.Fragment.performResume(Fragment.java:2235)
                                                                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1346)
                                                                      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                      at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2898)
                                                                      at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223)
                                                                      at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:509)
                                                                      at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:498)
                                                                      at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:172)
                                                                      at android.app.Activity.performResume(Activity.java:7016)
                                                                      at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4145)
                                                                      at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4250) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:158) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:7229) 
                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

这是我在logcat中得到的:

$(window).load(function() {
   $('head').append('<link rel="manifest" href="/manifest.json">');
})

为什么会这样?我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

请注意

Caused by: java.lang.IllegalStateException
at android.media.MediaPlayer._start(Native Method)

当app关闭时,我认为,MediaPlayer的状态未得到妥善处理。在重新启动应用程序时,媒体播放器的状态不同,不支持开始播放。

我认为,当你关闭应用程序时,会调用onPause(),释放MediaPlayer实例。但是,当您重新启动应用程序时(可能是从任务管理器的后台启动应用程序),没有初始化的MediaPlayer,您尝试播放媒体。