Below shown is the code, i am using to get values from the intent
Bundle extras = intent.getExtras();
extras object has the follwoing information
Bundle[{message=Order #400000063 is Ready for pickup, android.support.content.wakelockid=2, collapse_key=do_not_collapse, from=552489062080, e_id=364}]
When I say
extras.getString("message");
returns null. I am not sure how to get the values ?
In your Activity1:
Intent i = new Intent(Activity1.this,Activity2.class);
i.putExtra("message", "string_value");
startActivity(i);
In your Activity2:
// do a try/catch block or check
//if getIntent().getStringExtra("message") is null
String str = getIntent().getStringExtra("string_tag");
Probably you are writing different tag name ..
Use the same tag name which you used while sending data with Intent.
while sending data if you used code as
Intent i = new Intent(Activity1.this,Activity2.class);
i.putExtra("TAG_NAME", "string_value");
startActivity(i);
then use code below as
String str = getIntent().getStringExtra("TAG_NAME");
try it...
Related
This is my code for the .putExtra:
String url = "test";
startActivity(new Intent(MainActivity.this, RelationshipRemoved.class)
.putExtra("userInfo", urlTwo));
How do I call the value urlTwo in another file?
You can receive the value in another Activity (not just another file) reading the value from the received bundle, like this:
String userInfo = getIntent().getStringExtra("userInfo");
or
String userInfo = getIntent().getExtras().getString("userInfo");
Example:
Activity sending an intent:
Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
intent.putExtra("userInfo", "abcdef123456");
startActivity(intent);
ActivityTwo receive the data stored :
String receivedValue = getIntent().getStringExtra("userInfo");
the variable receivedValue will contain the string value "abcdef123456".
Sorry if we're doing anything wrong, we just started a crash course in android and we are trying to pass a value using the bundle but it does not show any error, it only crashes after the attempt. Here is the code block below.
ps, pls feel free to edit the post if you see anything wrong with it.
Bundle b = new Bundle(); //to pass values in meals.java
b.putStringArray("breakfast1" , new String[]{breakfast1[0]});
Intent gene = new Intent(Calories.this, Days.class);
//to pass the activity in another activity
gene.putExtras(gene);
startActivity(gene);
//second.java bundle receiving code block
break1 = (TextView) findViewById(R.id.break1);
Intent gene = getIntent();
String[] break2 = gene.getStringArrayExtra("breakfast1");
break1.setText(break2[0]);
Change gene.putExtras(gene); to gene.putExtras(b); and retrieve bundle using b = getIntent().getExtras()
FirstActivity
Bundle b = new Bundle(); //to pass values in meals.java
b.putStringArray("breakfast1" , new String[]{breakfast1[0]});
Intent gene = new Intent(Calories.this, Days.class);
//to pass the activity in another activity
gene.putExtras(b); //put bundle to intent
startActivity(gene);
In Second Activity Second.java
break1 = (TextView) findViewById(R.id.break1);
Intent gene = getIntent();
Bundle b = gene.getExtras(); //get bundle from intent
String[] break2 = b.getStringArrayExtra("breakfast1"); //get array list from bundle
break1.setText(break2[0]);
replace with this.
Bundle b = new Bundle(); //to pass values in meals.java
b.putStringArray("breakfast1" , new String[]{breakfast1[0]});
Intent gene = new Intent(Calories.this, Days.class);
//to pass the activity in another activity
gene.putExtras(b); // put b not gene
startActivity(gene);
//second.java bundle receiving code block
break1 = (TextView) findViewById(R.id.break1);
Intent gene = getIntent();
String[] break2 = gene.getStringArrayExtra("breakfast1");
break1.setText(break2[0]);
Please try this
Bundle b = new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i = new Intent(context, Class);
i.putExtras(b);
And for receiving side
Bundle b = this.getIntent().getExtras();
String[] array = b.getStringArray(key);
Help me modify with necessary changes needed to use the value/string(number) passed by user for phone-calling that string itself
Intent phnIntent = new Intent(Intent.ACTION_CALL);
phnIntent.setData(Uri.parse("tel:+91987654321"));
you can use like this :
String strTelNo = "+91987654321";
Intent intent = new Intent("android.intent.action.CALL");
Uri data = Uri.parse("tel:"+ strTelNo );
intent.setData(data);
startActivity(intent);
Try this link.
Make sure you add the necessary permission in the Android Manifest.
<uses-permission android:name="android.permission.CALL_PHONE" />
Just add the line startActivity(phnIntent);
EDIT:
Activity A
Intent someIntent = new Intent(A.this, B.class);
someIntent.putExtra("phoneNumber", number);
startAcitivty(someIntent);
Acitivity B
Bundle extras = getIntent().getExtras();
String number = extras.getInt("phoneNumber");
Use the number string to make the call.
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 ) );
add following code after intent:
Bundle extras = intent.getExtras();
String exampleString = extras.getString(ProjectManager.ID);
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);
}
Try This to Receive Extra:
Bundle extras = getIntent().getExtras();
String id;
if (extras != null) {
id= extras.getString(key);
}
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.
To retrieve the extras in the new activity:
String valueOfExtra;
Intent i = getIntent();
//check first
if(i.hasExtra("extra1")){
valueOfExtra = i.getStringExtra("extra1");
}
I know it's possible to share a text message with ACTION_SEND by specifying Intent.EXTRA_TEXT. Same approach works for images - Intent.EXTRA_STREAM.
But how can I add both text and image to the same intent?
you can send text and image via intent like
If you are sending using Intent ACTION then,
To send only one data either text or stream use,
Intent intent = new Intent(Intent.ACTION_SEND);
To send more then one data at a time use,
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
Normally to send from one specific Activity to any another specific activity,
Send
Bitmap bmp = "Your Bitmap";
String txt = "Text";
Intent intent = new Intent(ActivityName.this,SecondFile.class);
intent.putExtra("Text",txt);
intent.putExtra("Img",bmp);
startActivity(intent);
Receive
Intent intent = this.getIntent();
String txt = intent.getStringExtra("Text");
Bitmap bmp = intent.getParcelableExtra("Img");
You could add as many extras as you want to the same Intent :
intent.putExtra(Intent.EXTRA_STREAM,imgUri);
intent.putExtra(Intent.EXTRA_TEXT,text);
I hope I didn't get your question wrong.