简体   繁体   English

当我将其移动到后台时,为什么我的Android应用程序停止?

[英]Why does my Android app stops, when I move it to the background?

I'm developing an Android application and I have the following code lines: 我正在开发一个Android应用程序,并且具有以下代码行:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {
        moveTaskToBack(true);
        return true;
    }

    [... SOME MORE CODE ...]

}

When I test it on the emulator, it works perfectly and it closes the app and opens it at the some point as before. 当我在模拟器上对其进行测试时,它可以完美运行,并且可以关闭该应用程序,并像以前一样在某个时候打开它。 But when I load the APK on a real device, it always stops the application and starts it new, when I open it again. 但是,当我在真实设备上加载APK时,当我再次打开它时,它总是会停止应用程序并重新启动它。 With the loading screen. 随着加载屏幕。

Where is the problem? 问题出在哪儿?

Have you tried saving the state of the activity ? 您是否尝试保存活动状态? the solution is here 解决方案在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我按下按钮后我的应用程序停止运行 - Why does My app stops after i press the button 当我从 EditText 中删除所有内容时,为什么我的应用程序停止了? - Why my app stops when I delete all from EditText? 为什么我的“游戏”背景发生了变化? - Why does the Background of my “game” move? 我的 Android 11 应用程序在用户将其置于后台时停止运行,除非手机已连接到电源 - My Android 11 app stops running when the user puts it into the background unless the phone is connected to power 我的应用程序在构建时没有任何错误,但是当我在手机上运行它时它停止工作 - my app does not have any errors when it builds, however, it stops working when I run it on my phone 为什么当我关闭我的应用程序时,我的 android 应用程序活动会重新打开 - Why does my android apps activitie reopen when I close my app 为什么当我开始一项新活动时我的背景消失了? - why does my background disappear when i start a new activity? 当我在活动开始时点击垃圾邮件时,为什么我的 Android Studio 应用程序会崩溃? - Why does my Android studio App crash when I spam click at the beginning of an activity? Android教程-为什么当我尝试访问现有的文本视图时我的应用程序崩溃 - Android Tutorials — Why does my app crash when I try to access an existing Text View 为什么更改背景后Android Activity会移动按钮? - Why does Android Activity move button after changing background?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM