Update Fragment Ui With Data Passed From Activity
My Requirement : My MainActivity receives data from other app. MainActivity is listed as shareable. Now, I need to pass this data to a fragment in MainActivity and update the fragm
Solution 1:
Just add a proper method in your fragment, something like this:
publicvoidreceiveURL(String input){
//to handle what you want to pass to the fragment
}
And in your mainActivity call you can do something like this:
YourFragmentfragment= (YourFragment)getSupportFragmentManager.findFragmentById(R.id.your_fragment);
fragment.receive(sharedUrl);
Solution 2:
I'm assuming you already added the fragment via fragmentManager.add(..)
so the fragment is already on the layout.
If this is true, then your AddTab fragobj = new AddTab()
makes no sense since the Fragment already exists.
You need to either store a reference to this fragment in the activity, or use fragmentManager.findFragmentById()
or findFragmentByTag()
.
Then follow what Saeed says
Post a Comment for "Update Fragment Ui With Data Passed From Activity"