android - Send String from an Activity to a Fragment of another Activity -


i have 2 activities (a , b) , fragment f fragment f contained in activity b i'd send strings activity fragment f how can that? thanks!

first, you'll send string activity b. example:

intent intent = new intent(this, youractivityclass.class); intent.putextra("mystring", "this string"); startactivity(intent); 

then later read string activity b , inject fragment before executing fragment-transaction. example:

bundle args = new bundle(); args.putstring("mystring", getintent().getextras().getstring("mystring")) yourfragment.setarguments(args); 

later, use getarguments() in fragment retrieve bundle.


or alternatively, use following in fragment directly access activity intent , fetch required value:

string str = getactivity().getintent().getstringextra("mystring"); 

for more info, read this.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

java - How to create Table using Apache PDFBox -

mpi - Why is MPI_Bsend not returning error even when the buffer is insufficient to accommodate all the messages -