Android - GetIntent() From A Fragment


Answer :

You can use a getIntent() with Fragments but you need to call getActivity() first. Something like getActivity().getIntent().getExtras().getString("image") could work.


It's not that you can't pass data, it's that you don't want to.

From the Fragment documentation:

Often you will want one Fragment to communicate with another, for example to change the content based on a user event. All Fragment-to-Fragment communication is done through the associated Activity. Two Fragments should never communicate directly.

If you take a look at the Fragment documentation, it should walk you through how to do this.


If you want get intent data, you have to call Fragment's method getArguments(), which returns Bundle with extras.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?