简体   繁体   English

Android登录名并将名字和名字粘贴到用户区域

[英]Android Login and pasting first and secondnames to user area

Hi guys I need your help, I am stuck in that place. 大家好,我需要您的帮助,我被困在那个地方。 I would like to have first and secondname pasted to user area to appear automatically after logging in. The problem is the user area is in different java class than the one which comes next after log in activity. 我希望将名字和第二名粘贴到用户区域以在登录后自动出现。问题是用户区域与登录活动后的下一个区域不在同一个Java类中。

Here is the part of the code from log in activity 这是登录活动中的代码部分

    if(session.loggedin()){
        startActivity(new Intent(LoginActivity.this, MainActivity.class));
        finish();
    }



    btnlogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final String email = etemail.getText().toString();
            final String password = etpassword.getText().toString();

            Response.Listener<String> responseListener = new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    try {
                        JSONObject jsonResponse = new JSONObject(response);
                        boolean success = jsonResponse.getBoolean("success");

                        if(success){

                            String firstusername = jsonResponse.getString("firstusername");
                            String secondusername = jsonResponse.getString("secondusername");

                            Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                            intent.putExtra("firstusername", firstusername);
                            intent.putExtra("secondusername", secondusername);

                            startActivity(intent);
                            finish();

                            session.SetLoggedIn(true);

And here is the code from the user activity 这是来自用户活动的代码

/*
    Code for showing users name and last name
     */

    final TextView firstUsername = (TextView) findViewById(R.id.firstusername);
    final TextView secondUsername = (TextView) findViewById(R.id.secondusername);

    Intent intent = getIntent();
    String firstusername = intent.getStringExtra("firstusername");
    String secondusername = intent.getStringExtra("secondusername");

    firstUsername.setText(firstusername);
    secondUsername.setText(secondusername);

Now I uploaded some more code. 现在,我上传了更多代码。

You approach seems correct. 您的方法似乎正确。 First you should check if your extras are not null( for some reason). 首先,您应该检查您的临时演员是否不为空(由于某种原因)。 Bundle extras = getIntent().getExtras(); 捆绑包= getIntent()。getExtras(); if (extras!= null) 如果(extras!= null)

Or if the variables you pass(the one you deserialize from json) to intent are not empty 或者,如果您传递给intent的变量(从json反序列化的变量)不为空

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM