Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 关闭应用程序后onDestroy崩溃_Android_Android Activity_Media Player_Ondestroy - Fatal编程技术网

Android 关闭应用程序后onDestroy崩溃

Android 关闭应用程序后onDestroy崩溃,android,android-activity,media-player,ondestroy,Android,Android Activity,Media Player,Ondestroy,在重写onDestroy方法后,我遇到了一些问题。 我的应用程序是一个音乐播放器,如果没有播放音乐,我需要使用mediaplayer的实例在某个时候强制释放它。 这是我到目前为止的代码,为了实现这个技巧,我已经重写了onKeyDown()和onDestroy()方法: 就是这样,现在当我想关闭应用程序时,只需按下后退按钮,应用程序就会调用onPause()onStop()和onDestroy()方法,对吗? 无论如何,有时关闭手机后,手机会冻结4-5秒,并显示一条消息:“程序应用程序已关闭”。

在重写onDestroy方法后,我遇到了一些问题。 我的应用程序是一个音乐播放器,如果没有播放音乐,我需要使用mediaplayer的实例在某个时候强制释放它。 这是我到目前为止的代码,为了实现这个技巧,我已经重写了onKeyDown()和onDestroy()方法:

就是这样,现在当我想关闭应用程序时,只需按下后退按钮,应用程序就会调用onPause()onStop()和onDestroy()方法,对吗? 无论如何,有时关闭手机后,手机会冻结4-5秒,并显示一条消息:“程序应用程序已关闭”。 我知道我做错了什么,但我不知道是什么,我需要一些帮助。
谢谢你的建议

super.onDestroy()
如果重写,则必须是
onDestroy
方法的第一个调用。

super.onDestroy()
如果重写,则必须是
onDestroy
方法的第一个调用。

试试下面的代码,它对我有用

@凌驾

public void onDestroy() {

    mediaPlayer.stop();

    super.onDestroy();

        }

}

试试下面的代码它对我有用

@凌驾

public void onDestroy() {

    mediaPlayer.stop();

    super.onDestroy();

        }

}

检查mnotify是否为null,同时检查mp是否为null tip super.ondestory();必须是onDestroy()中的第一个语句我已经说出了你所说的,但问题仍然在那里检查mnotify是否为null也检查mp是否为null tip super.onDestroy();必须是onDestroy()中的第一句话我已经说出了你说的话,但问题仍然存在