[英]Close android app and it's running features on Home press
I know all of you say that you shouldn't force your app to close, but I kinda need it. 我知道你们所有人都说您不应该强制关闭应用程序,但我有点需要它。 The thing is, my app has vibrate and sound (mediaplayer) at the same time. 问题是,我的应用程序同时具有振动和声音(媒体播放器)功能。 So when the user presses "Home", it should stop those two and "close the app down". 因此,当用户按下“主页”时,应停止这两个操作并“关闭应用程序”。 Right now NOTHING happens when I press Home - actually it kinda freezes (but sound and vibrate goes on) - until the app crashes. 现在,当我按Home键时,什么都不会发生-实际上它会冻结(但声音和振动还在继续)-直到应用程序崩溃为止。
if (mpButtonClick.isPlaying())
{mpButtonClick.pause();
mpButtonClick.seekTo(0);
vibr.cancel();
}
else
{
mpButtonClick.start();
int length = mpButtonClick.getDuration();
vibr.vibrate(length);
}
I also have a onDestroy and onBackPressed (they're similar): 我也有一个onDestroy和onBackPressed(它们是相似的):
mpButtonClick.stop();
vibr.cancel();
super.onDestroy();
System.runFinalizersOnExit(true);
System.exit(0);
onBackPressed works perfectly. onBackPressed可以完美运行。 But "Home"-button crashes. 但是“主页”按钮崩溃。 Any ideas? 有任何想法吗?
Thanks in advance. 提前致谢。
I know all of you say that you shouldn't force your app to close, but I kinda need it. 我知道你们所有人都说您不应该强制关闭应用程序,但我有点需要它。
No, you do not. 你不可以。
So when the user presses "Home", it should stop those two 因此,当用户按下“主页”时,应停止这两个
Stop the media playback and vibration in onPause()
or onStop()
. 在onPause()
或onStop()
停止媒体播放和振动。
But "Home"-button crashes. 但是“主页”按钮崩溃。 Any ideas? 有任何想法吗?
Use adb logcat
, DDMS, or the DDMS perspective in Eclipse to examine LogCat and look at the stack trace associated with your crash. 在Eclipse中使用adb logcat
,DDMS或DDMS透视图检查LogCat并查看与崩溃相关的堆栈跟踪。 Consider opening up a fresh question with details of the stack trace, along with the associated source code, so people can help you with this crash. 考虑打开一个有关堆栈跟踪详细信息以及相关源代码的新问题,以便人们可以帮助您解决此崩溃问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.