简体   繁体   中英

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:

@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. With the loading screen.

Where is the problem?

Have you tried saving the state of the activity ? the solution is here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM