Reputation: 2527
I need to pass information between two activities, but for some reason the information isn't sent / recieved.
LogCat doesn't give me any errors. The dubugger clearly shows something is added to the intent (variabl: mExtras), but it's hard to interpret exactly what is added. After that it gives me "source not found" and doesn't help me further.
But first things first. Am I doing things right so far?
Sending:
Intent intent = new Intent ( this, TaskListActivity.class );
intent.putExtra ( ProjectManager.ID, mId.toString () );
startActivity ( intent );
Recieving:
Intent intent = getIntent ();
mId = UUID.fromString ( intent.getStringExtra ( ProjectManager.ID ) );
Upvotes: 5
Views: 18223
Reputation: 1
None of the above worked for me when trying to retrieve EXTRA_TEXT. I was incorrectly trying to retrieve it via:
String data = extras.getString("EXTRA_TEXT");
To I had to remove the quotes and prefix EXTRA_TEXT with 'Intent.'
caller:
Intent intent = new Intent(this, AboutActivity.class);
intent.putExtra(Intent.EXTRA_TEXT, "hello from menu item selected");
startActivity(intent);
receiver:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String data = extras.getString(Intent.EXTRA_TEXT);
TextView tv = findViewById(R.id.myAboutText);
tv.setText(data);
}
Upvotes: 0
Reputation: 2903
To retrieve the extras in the new activity:
String valueOfExtra;
Intent i = getIntent();
//check first
if(i.hasExtra("extra1")){
valueOfExtra = i.getStringExtra("extra1");
}
Upvotes: 0
Reputation: 2147
In FirstActivity.java write these code.
Intent i = new Intent(FirstActivity.this,SecondActivity.class);
i.putExtra("KEY",value);
startActivity(i);
In SecondActivity.java:
Bundle extras=getIntent().getExtras();
String name=extras.getString("key"); //if data you are sending is String.
int i=extras.getInt("key"); //if data you are sending is integer.
Upvotes: 0
Reputation: 1347
Try This to Receive Extra:
Bundle extras = getIntent().getExtras();
String id;
if (extras != null) {
id= extras.getString(key);
}
Upvotes: 0
Reputation: 10969
what is ProjectManager.ID
?, you should pass same uniquekey
while recieving data from putExtra even way of receiving data is wrong, check below code:
Sending:
Intent intent = new Intent ( this, TaskListActivity.class );
intent.putExtra (ProjectManager.ID, mId.toString () );
startActivity ( intent );
Recieving:
Bundle extras = intent.getExtras();
if(extras!=null){
String _Str = extras.getString(ProjectManager.ID);
}
Upvotes: 1
Reputation: 11948
add following code after intent:
Bundle extras = intent.getExtras();
String exampleString = extras.getString(ProjectManager.ID);
Upvotes: 1