What Intent.putExtra does

I am new to android and I use intentions to transfer data from one Activity to another. I just wanted to know if the link to the object or a copy of the object is sending a second activity.

+6
source share
2 answers

Intent.putExtra sends a copy of the object, this is not the same link when you receive additional information from the intent that you do where the new link is located.

+5
source

intent.putExtra is used to send information between activities. Here is an example

Use this to β€œput” a file

Intent i = new Intent(FirstScreen.this, SecondScreen.class); String keyIdentifer = null; i.putExtra("STRING_I_NEED", strName); 

Then, to get the value, try something like:

 String newString if (savedInstanceState == null) { extras = getIntent().getExtras(); if(extras == null) { newString= null; } else { newString= extras.getString("STRING_I_NEED"); } } else { newString= (String) savedInstanceState.getSerializable("STRING_I_NEED"); } 
+1
source

All Articles