我的Andr​​oid应用程序不会退出时pressing后退按钮 [英] My Android App Does Not Exit When Pressing Back Button

查看:161
本文介绍了我的Andr​​oid应用程序不会退出时pressing后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid编程和我写的只实现了 Activity.OnCreate 方法的应用。我希望回到previous视图(这有可能成为主屏幕由于基本意图过滤器我有)由pressing BACK按钮,但事实并非如此。我设法做,只有pressing HOME键。 (我已经测试我的应用程序在多种设备和它的行为是一样的。)已经其他人走进了同样的问题?解决办法是什么? (我的应用程序的混帐回购协议是在这里: https://github.com/falcondai/android_lab1

以下是我没能很好地退了出去活动(BACK键对所有其他活动正常工作):

 公共类NameGetterActivity扩展活动
{
    私有静态最后弦乐TAG =NameGetterActivity;    私人的EditText name_fld;
    私人按钮的submit_btn;
    私人按钮test_btn;    公共无效的onCreate(捆绑savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.name_getter);        name_fld =(EditText上)this.findViewById(R.id.editText1);
        的submit_btn =(按钮)this.findViewById(R.id.button1);
        test_btn =(按钮)this.findViewById(R.id.button2);        submit_btn.setOnClickListener(
                新OnClickListener(){
                    公共无效的onClick(视图v){
                        Log.d(TAG,name_fld.getText()的toString());                        意图I =新意图(NameGetterActivity.this,HelloWorldActivity.class);
                        i.putExtra(名,name_fld.getText()的toString());
                        startActivity(ⅰ);
                    }
                }
            );        test_btn.setOnClickListener(
                新OnClickListener(){
                    公共无效的onClick(视图v){
                        Log.d(TAG,传感器活动按钮pressed);                        意图I =新意图(NameGetterActivity.this,SensorActivity.class);
                        startActivity(ⅰ);
                    }
                }
            );
    }}


解决方案

您layerout XML文件中使用的MediaController作为布局根,与LinearLayout中更换

I am new to Android programming and I wrote an app implementing only the Activity.OnCreate method. I expected to go back to the previous view (which has to be the home screen due to the basic intent-filter I have) by pressing the BACK button but it does not. I managed to do that only by pressing the HOME button. (I have tested my app on multiple devices and it behaves the same.) Has everybody else went into the same problem? What is the solution? (the git repo of my app is here: https://github.com/falcondai/android_lab1)

The following is the Activity I failed to back out properly (the BACK key works fine for all other activities):

public class NameGetterActivity extends Activity 
{
    private static final String TAG = "NameGetterActivity";

    private EditText name_fld;
    private Button submit_btn;
    private Button test_btn;

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.name_getter);

        name_fld = (EditText)this.findViewById(R.id.editText1);
        submit_btn = (Button)this.findViewById(R.id.button1);
        test_btn = (Button)this.findViewById(R.id.button2);

        submit_btn.setOnClickListener(
                new OnClickListener() {
                    public void onClick(View v) {
                        Log.d(TAG, name_fld.getText().toString());

                        Intent i = new Intent(NameGetterActivity.this, HelloWorldActivity.class);
                        i.putExtra("name", name_fld.getText().toString());
                        startActivity(i);
                    }
                }
            );

        test_btn.setOnClickListener(
                new OnClickListener() {
                    public void onClick(View v) {
                        Log.d(TAG, "sensor activity button pressed");

                        Intent i = new Intent(NameGetterActivity.this, SensorActivity.class);
                        startActivity(i);
                    }
                }
            );
    }

}

解决方案

your layerout xml file use MediaController as layout root, replace it with LinearLayout

这篇关于我的Andr​​oid应用程序不会退出时pressing后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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