Android登录应用程序-显示电子邮件 [英] Android Login App - display the email

查看:82
本文介绍了Android登录应用程序-显示电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用简单的登录示例.成功登录后,在Hello消息后显示用户的电子邮件.

Use the simple login example. Upon successful login, display the email of the user after the Hello message.

我的问题是如何显示发送给内部活动的电子邮件

My question is how to display the email to Inner Activity

代码是

LoginAcitvity

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        final EditText email = (EditText) findViewById(R.id.emailText);
        final EditText password = (EditText) findViewById(R.id.passwordText);

        final Button loginButton = (Button) findViewById(R.id.loginButton);

        loginButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                if (authenticate(email.getText().toString(), password.getText().toString())) {

                    Intent innerIntent = new Intent(LoginActivity.this,
                            InnerActivity.class);

                    startActivity(innerIntent);


                } else {
                    // uname.setText("");
                    password.setText("");
                }
            }
        });

    }


    private boolean authenticate(String email, String password) {
        // Return random value. Later we will contact the server here

        if(email.equals("foo@bar.123") && password.equals("hello")) {
            return true;
        }
        if(email.equals("bar@foo.123") && password.equals("world")) {
            return true;
        }
        return false;
    }
}

InnerAcitvity

public class InnerActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inner);

    }
}

推荐答案

使用意图.将其写入LoginActivity的 loginButton.setOnClickListener :

Use Intent. Write this in loginButton.setOnClickListener of LoginActivity:

Intent innerIntent = new Intent(LoginActivity.this,InnerActivity.class);
innerIntent.putExtra("email",email.getText().toString());
startActivity(innerIntent);

InnerActivity.java

String email=getIntent().getExtras().getString("email");
txtView.setText(email);

在继续讨论其他主题之前,我将建议您学习Intent的实际含义及其广泛的功能.请参见,以及

Before proceeding to other topics I will recommend you to learn what a Intent actually is and its vast functionalities. See this and also this.

这篇关于Android登录应用程序-显示电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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