Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I don't see any big difference between them but the first one asks the help of Bundle while the other one directly gets the string from the intent. It seems to me that this is a standard procedure as it is always what I see from the other code.

MainActivity:

Java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    TextView usersNameMessage = (TextView) findViewById(R.id.users_name_message);

    String nameSentBack = data.getStringExtra("UsersName");

    usersNameMessage.append(" " + nameSentBack);
}


SecondActivity:

Java
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstaceState);
	
	setContentView(R.layout.second_layout);
	
	// gets the intent that called the SecondScreen activity.
	Intent activityThatCalled = getIntent();
	// gets the data passed by the previous activity by providing the name.
	String previousActivity = activityThatCalled.getExtras().getString("nameOfThedataToBePassed");

}


What I have tried:

I tried searching about it but haven't found an answer specific to this usage.
Posted
Updated 26-Jul-16 21:42pm

1 solution

getExtras[^] first returns a Bundle, while getStringExtra[^] directly returns a string.
 
Share this answer
 
Comments
Doughnatch 27-Jul-16 3:48am    
I already know that but is there a more significant reason to be doing it that way if I can just use getExtras() alone or vice versa?
Richard MacCutchan 27-Jul-16 4:08am    
I don't know. I suggest reading the documentation and running some test applications.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900