What I usually do, and I believe that this is what Google intended for developers, is also to still get extra functions from Intent to Activity , and then pass any extra data to fragments, creating them with arguments.
Actually an example on the Android dev blog that illustrates this concept, and you'll see this in a few API examples. Although this specific example is for API 3.0+ fragments, the same thread applies when using FragmentActivity and Fragment from the support library.
First, you extract the presets of intent as usual in your activity and pass them as arguments to the fragment:
public static class DetailsActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
Instead of calling the constructor directly, it might be easier to use a static method that connects the arguments to the fragment for you. This method is often called newInstance in the examples provided by Google . Actually there is a newInstance method in DetailsFragment , so I'm not sure why it is not used in the snippet above ...
In any case, all additional functions provided as an argument when creating the fragment will be available by calling getArguments() . Since this returns a Bundle , its use is similar to the use of additional functions in Activity .
public static class DetailsFragment extends Fragment { public static DetailsFragment newInstance(int index) { DetailsFragment f = new DetailsFragment();
Mh. Jul 9 2018-12-12T00: 00Z
source share