eclipse Android - 单击按钮时关闭活动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22892732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:38:11  来源:igfitidea点击:

Android - Close activity on button click

androideclipsebuttonkill

提问by Tamas Koos

I have a Bus timetable app with a lot of activity (around 120). It is working smoothly, but after opening several activities, it gets slower. So I have buttons that opens an other activity. I want to kill the former activity after the other is opened. How can I make it? Thanks in advance.

我有一个包含大量活动(大约 120 次)的巴士时刻表应用程序。运行很顺利,但是打开几个活动后,速度变慢了。所以我有打开其他活动的按钮。我想在另一个活动打开后杀死前一个活动。我怎样才能做到?提前致谢。

My button click action:

我的按钮点击动作:

addListenerOnButton();
}


public void addListenerOnButton() {

final Context context = this;

button101 = (Button) findViewById(R.id.button101);

button101.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        Intent intent = new Intent(context, B10oda.class);
        startActivity(intent);   
    }
});

回答by Raghunandan

Call finish()

称呼 finish()

Intent intent = new Intent(context, B10oda.class);
startActivity(intent);
finish();

But think again if you really want to finish the Activity. You could do some profiling and find out why your app is running slow.

但是,如果您真的想完成活动,请再想一想。您可以进行一些分析并找出您的应用程序运行缓慢的原因。

Also 120 Activities seems too much. See if you could change your design and reduce the number of Activities.

还有 120 个活动似乎太多了。看看你是否可以改变你的设计并减少活动的数量。