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

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -