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.