简体   繁体   中英

How to solve passing value from one activity to another activity by using new intent?

I am passing value from one activity to another activity by using a new Intent as like follows code but when I want to get the passing value from another activity it shows that the value is null.

First Activity from where the data is passing

Intent intent = new Intent();
            Log.e("Pass Profile Name: ",""+profileName.getText());
            intent.putExtra("profileName",profileName.getText());
            setResult(RESULT_OK,intent);
            finish();

Second Activity getting the passing data code

String pName = getIntent().getStringExtra("profileName");
        Log.e("Profile Name",""+pName);

and the pName is null here.Can someone help me out why this is happened...

Try it like this way

Intent intent=new Intent(this,youractivity.class);
intent.putExtra("profileName",profileName.getText().toString);
startActivity(intent);

for recieving

Intent intent=getIntent();
String pName = intent.getStringExtra("profileName");

If profileName is an Edittext, you need to add .toString after you get the Editable profileName.getText()

Like this:

intent.putExtra("profileName",profileName.getText().toString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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