杀死后退按钮活动 [英] Kill Activity on back button

查看:126
本文介绍了杀死后退按钮活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我得到了一个活动,它启动时,它加载图像从互联网上,并试图以节省内存,当活动是左(后退按钮的存在pressed),我想活动转储(摆脱所有的字符串,并且在它的图像)。所以,我想做到这一点的最好办法就是杀了活动。好吧,我似乎无法找出回调时,后退按钮是pressed,所以我一直在试图使用的onPause和的onStop回调的任务,但糟蹋的方式强行关闭我的应用程序。我试着这样

Ok, I got an activity, that when it starts, it loads an image from the internet, and, trying to save memory, when the activity is left (the back button being pressed), I want the activity to dump (get rid of all the strings and images that are in it). So, I figure the best way to do this is to just kill the activity. Well, I cant seem to figure out the callback for when the backbutton is pressed, so I have been trying to use the onPause and onStop callbacks for the task, but botch ways force close my app. Im trying this

public void onPause() {
this.finish();
}
public void onStop() {
finish();
}

香港专业教育学院尝试了这种多变化,但他们都不工作。有任何想法吗?

Ive tried multiple variations of this, but none of them seem to work. Any ideas?

推荐答案

添加到您的活动

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK))
    {
        finish();
    }
    return super.onKeyDown(keyCode, event);
}

这篇关于杀死后退按钮活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆