android - How to transfer string data from main activity to another Activity -


this question has answer here:

i need make fragment (dialog box, whatever) content changes depending on user selects. means need transfer string data main activity activity responsible fragment. how do this?

you can add extras intent use when starting activity inside of another.

so, example, wherever handle users selection in first activity (let's call activity a) can send string activity b this:

intent intent = new intent(activitya.this, activityb.class); intent.putextra("stringkey", "stringvalue"); startactivity(intent); 

the first parameter key used reference need, , value whatever string want passed next activity.

then, somewhere in activity b can read string so:

if(getintent().getextras().containskey("stringkey"){    string passedstr = getintent().getstringextra("stringkey"); } 

and original "stringvalue" assigned 'passedstr'.


Popular posts from this blog

javascript - Js, document.getElementById("ID").innerHTML, error -

jquery - jqGrid update specific column data with out refreshing the entire column? -

objective c - Is there a way in OCMockito to make stubs fail when an unknown method is called? -