从关闭我的应用程序prevent后退按钮我的、应用程序、按钮、prevent

由网友(活该卑微)分享简介:我使用下面的code。在我的应用程序的活动,以prevent从收盘回到我的应用程序。I am using the following code in my application's activity to prevent it from closing my app on back./* Prevent app...

我使用下面的code。在我的应用程序的活动,以prevent从收盘回到我的应用程序。

I am using the following code in my application's activity to prevent it from closing my app on back.

/* Prevent app from being killed on back */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        // Back?
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // Back
            moveTaskToBack(true);
        }

        // Return
        return super.onKeyDown(keyCode, event);

    }

这是行不通的。该应用程序被设置为Android 1.6的(API等级4)兼容。点击我的应用程序图标重新启动我在飞溅的活动应用程序(这是主要的)。我怎样才能prevent我的应用程序的关闭背?

It does not work. The app is set to be Android 1.6 (API Level 4) compatible. Clicking on my application icon restarts my app at a Splash activity (which is the Main). How can I prevent my app from closing on back?

推荐答案

您是否尝试过把在else块所以它如果密钥只有所谓的来电没有键code_BACK

Have you tried putting the super call in an else block so it is only called if the key is not KEYCODE_BACK ?

/* Prevent app from being killed on back */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        // Back?
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // Back
            moveTaskToBack(true);
            return true;
        }
        else {
            // Return
            return super.onKeyDown(keyCode, event);
        }
    }

不过说实话,你不能依靠这一点,因为一旦你的应用程序放置在后台,在任何时候都有可能被回收的系统回收内存。

In all honesty though, you can't rely on this because once your app is placed in the background, at any moment it could be recycled for the system to reclaim memory.

阅读全文

相关推荐

最新文章