I have this app in which im using fragments, but somehow everytime I start the app, every activity(fragment) is started two times. I\'m banging my head about this but I cannot f
Maybe using a newInstance method will correct this starting of two fragments. Ad populum I see alot of newInstance code when I'm looking at fragment examples.
public class MainFragment extends Fragment {
public static Fragment newInstance(int instance# pass in receipieces and cats here) {
MainFragment f = new MainFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putParcelableArrayList("all", recepies);
args.putSerializable("cats", cats);
args.putParcelableArrayList(Constants.MAINRECEPIES, mainRecepies);
args.putBoolean("search", true);
fragment.setArguments(args);
return f;
}
meanwhile back in the activity that shows the fragment use new instance to start the fragment.
private void showMainFragment() {
Fragment fragment = MainFragment.newInstacne(instance# pass in recipies and cats here);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().add(R.id.content_frame, fragment)
.commit();
}