简体   繁体   English

关闭android应用,并在Home press上运行该功能

[英]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.

相关问题 将新闻事件发送到Android中正在运行的应用程序的按钮 - Sending press events to the buttons of a running app in Android Android:在某些设备上按“主页”按钮后,应用程序将无法回家 - Android: app won't go home after home button press on some devices Android 重新启动时运行应用程序导致 android 默认主屏幕未激活 - Android Running app on reboot causing android default home screen not activate 在android studio中按“后退”按钮后,应用程序仍然运行 - App remains running after press back button in android studio Android-按(主页按钮->应用程序快捷方式)时显示上次查看的活动 - Android - Show last viewed Activity When press (Home Button-->App Shortcut) 如何长按主页,后退或最近的应用程序按钮打开我的Android应用程序? - How to open my Android app on a long press of home, back or recent apps button? 在android中处理最近的应用程序点击和主页按下 - Handle Recent apps click and home press in android 如何在真正的安卓设备上按下“主页”按钮 - How to press 'Home' button on real android device 应用关闭后广播接收器仍然运行 - Android - Broadcast Receiver Still Running after app close - Android 基于功能模块化Android应用程序 - Modularizing android app based on features
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM