Android Intent.Getstringextra() Returns Null

intent.getStringExtra() returns null

in HomeActivity you are initializing intent as

intent = Intent()

This actually initializes the intent with a new intent object. That is not desired behavior, to achieve desired behavior use getIntent() instead of Intent().

Android intent.getStringExtra() return null

if(resultCode == 0){
//Intent intent = getIntent();
String name2 = data.getStringExtra("namev");
String email2 = data.getStringExtra("emailv");
String birthday2 = data.getStringExtra("birthdayv");

Log.d("AAA",">>>:"+name2);

Contact person = new Contact(name2,email2,birthday2);
allContact.add(person);
}}

you need to use the data not getIntent()

Android Intent.getStringExtra() returns null

When you insert your Extras trying adding .toString()

i.putExtra("Name", edt_name.getText().toString());

You are seeing the CharSequence value in there but you need to convert it to a String to call getStringExtra(). Obviously, just do this for the Strings. You see the correct value for your int because that is done correctly

Getting null value for Intent.getstringExtra()

Move this code inside onCreate

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

Intent wb = getIntent();
final String url = wb.getStringExtra("link");

if (savedInstanceState == null) {
webView.post(() -> webView.loadUrl(url));
}
}

intent.getStringExtra is always null

You are creating a brand new intent in the other activity, so it has no extras. In the new activity you need to call getIntent(), like this

Intent intent = getIntent(); // don't use 'new Intent()' here
String username = intent.getStringExtra("username");
Log.i("test3","username: "+username);

Note that calling getStringExtra just calls getExtras() internally, then getString(...), so it is the same as using getIntent().getExtras().getString(...)



Related Topics



Leave a reply



Submit