Intent.getstringextra() Returning Null
I really find this weird, I'm able to get other values except one. Here's my code: Intent intent = new Intent(this.context, SecondActivity.class); intent.putExtra('contact', n.getC
Solution 1:
In MainActivity.class
Intent myIntent=newIntent(MainActivity.this, ResultActivity.class);
Bundle bundle=newBundle();
bundle.putString("contact", n.getContact());
bundle.putString("email", n.getEmail());
bundle.putString("address", n.getAddress());
bundle.putString("test", "hello world");
myIntent.putExtra("MyPackage", bundle);
startActivity(myIntent);
In ResultActivity.class
Intent callerIntent=getIntent();
Bundle packageFromCaller=
callerIntent.getBundleExtra("MyPackage");
String contact =packageFromCaller.getString("contact");
String email =packageFromCaller.getString("email");
String address= packageFromCaller.getString("address");
String test= packageFromCaller.getString("test");
Hope. It will help you !!!
Solution 2:
use getApplicationContext() instead of this.context and use startActivity instead of context.startActivity
First Activity
Intent intent = newIntent(getApplicationContext(), SecondActivity.class);
intent.putExtra("test", "hello world");
startActivity(intent);
Second Activity
Intentintent= getIntent();
intent.getStringExtra("test");
Solution 3:
You need to add .toString() and the end of the method call on each putExtra
Intent intent = newIntent(this.context, SecondActivity.class);
intent.putExtra("contact", n.getContact().toString());
intent.putExtra("email", n.getEmail().toString());
intent.putExtra("address", n.getAddress().toString());
intent.putExtra("test", "hello world");
context.startActivity(intent);
Solution 4:
send data
Intent intent = newIntent(this.context,SecondActivity.class);
intent.putExtra("contact", n.getContact());
startActivity(intent);
get data
Bundle data = getIntent().getExtras();
contact = data.getString("contact");
Post a Comment for "Intent.getstringextra() Returning Null"