I have seen similar questions to that but most of them show passing bitmap between activities. Referring to this question, the accepted answer does not recommend using bundle while passing bitmap between two activities and suggest using intent extras instead. But since i am trying to pass bitmap between fragments, not activities, i cannot use intents and do not know what else to use other than bundle. Here is what i do to pass Bitmap between fragments: I pass bitmap to the activity through an interface, and then pass it to other fragment inside that interface.
//MyActivity.java
@Override
public void onMyFragmentFired(Bitmap bitmap) {
FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
args=new Bundle();
fragment = MyFragment.newInstance();
if(bitmap != null){
args.putParcelable("EXTRA_BITMAP", bitmap);
}
fragment.setArguments(args);
ft.add(fragment, "com.example.myfragment");
ft.commit();
}
I wonder whether i face any problems if bitmap is too large etc. Is there a better way to do this?
Thanks