Two EXTRA_MESSAGE from Intent - android

Can i have two extra messages on Intent that i can pass on another Activity? If yes, how does it work?
this is what I did:
Intent intent3 = new Intent(this, Start.class);
String message = o.getName();
String messages = o.getPath();
intent3.putExtra(EXTRA_MESSAGE, message);
intent3.putExtra(EXTRA_MESSAGE, messages);
startActivity(intent3);`
and on the Activity that will receive the message:
Intent intent3 = getIntent();
String message = intent3.getStringExtra(Browse.EXTRA_MESSAGE);
String messages = intent3.getStringExtra(Browse.EXTRA_MESSAGE);`

You have to change the KEY:
Intent intent3 = new Intent(this, Start.class);
String message = o.getName();
String messages = o.getPath();
intent3.putExtra(EXTRA_MESSAGE, message);
intent3.putExtra(EXTRA_MESSAGE_TWO, messages);
startActivity(intent3);

Not exactly like that, but it is easy to send multiple values. The first parameter to putExtra or getStringExtra is a key into a map of values so it must be unique. As long as you use a different key for each value you can put as many as you want in the intent.
For example:
Intent intent3 = new Intent(this, Start.class);
String message = o.getName();
String messages = o.getPath();
intent3.putExtra("name", message);
intent3.putExtra("path", messages);
startActivity(intent3);
Intent intent3 = getIntent();
String message = intent3.getStringExtra("name");
String messages = intent3.getStringExtra("path");`

This is a problem the way you have them. You need separate keys for each value. So for example
intent3.putExtra("msg1", message);
intent3.putExtra("msg2", messages);
then in your receiving Activity you can get them using the above keys. But you can add as many Extra values as you want.

Two different keys and messages will do it
Intent intent3 = new Intent(this, Start.class);
String message = o.getName();
String messages = o.getPath();
intent3.putExtra(EXTRA_MESSAGE1, message);
intent3.putExtra(EXTRA_MESSAGE2, messages);
startActivity(intent3);

Related

How i can send data variable to multiple activity at the same time?

String info = ((TextView) v).getText().toString();
String address = info.substring(info.length() - 17);
Intent intent1 = new Intent(DeviceList.this, MainActivity.class);
intent1.putExtra(EXTRA_ADDRESS, address);
startActivity(intent1);
Intent intent12 = new Intent(DeviceList.this, Room1.class);
i.putExtra(EXTRA_ADDRESS, address);
how i can send the same data at the same time using intent to multiple activity without start this activity ?

Sending multiple integers with intent

i am trying to send two values to another page, but everytime only one of them is working.Here is my code:
Sending:
Intent i = new Intent(getApplicationContext(),fight_1.class);
i.putExtra("deger2",ana_ekran_arti1_int);
startActivity(i);
Intent i = new Intent(getApplicationContext(),fight_1.class);
i.putExtra("deger", ana_ekran_can_int);
startActivity(i);
Taking:
int i = getIntent().getIntExtra("deger",-1);
int ii = getIntent().getIntExtra("deger2",-1);
arti1= ii;
fight_1_arti1.setText(arti1+"");
fight_1_can_int=i;
fight_1_can.setText(fight_1_can_int+"");
You are only sending one value you have to use the same intent without creating a new object.
I hope this helps
Intent i = new Intent(getApplicationContext(),fight_1.class);
i.putExtra("deger2", ana_ekran_arti1_int);
i.putExtra("deger", ana_ekran_can_int);
startActivity(i);

.putExtra into another file

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".

Android getting values from intent

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...

how to start an activity in handler

trying to trigger an Activity from a handler.
my other option is triggering from a broadcastReceiver.
this is what ive tried and it doesnt work.
public void handleMessage(Context context, Intent intent)
{
Log.v(tag,"handling message.........");
String messageString = intent.getExtras().getString("message");
C2DMMessage newC2DMMessage = new C2DMMessage(messageString);
Intent mIntent = new Intent(context,popad.class);
context.startActivity(mIntent);
String message_body = String.valueOf(newC2DMMessage.getParamValue("message_body"));
Toast.makeText(context, "message was recieved!!!!: '" + message_body + "'", Toast.LENGTH_LONG).show();
}
open to suggestions for a better way to start an activity.
Any errors you get in Logcat would be most helpful in your questions
Try changing :
Intent mIntent = new Intent(context,popad.class);
context.startActivity(mIntent);
To :
Intent mIntent = new Intent(context,popad.class);
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mIntent);

Categories

Resources