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? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -