When transferring a Bitmap from a fragment to an activation, I found such a bug - I use the FragmentStatePagerAdapter for the ViewPager, when I open the image in a separate window, 3 pages of the ViewPager fragment are written, 1 is the current, 2 is the previous one, 3 is the next, and it turns out that it is recorded and transmitted not the current image and the last third. The way to set viewPager.setOffscreenPageLimit (0) - does not work. Here are the logs:
D/PreviewActivity: onCreate a D/PageFragment: newInstance fragment D/PageFragment: newInstance fragment D/PageFragment: newInstance fragment D/PageFragment: onAttach fragment D/PageFragment: onCreate fragment: 2130837590 D/PageFragment: onAttach fragment D/PageFragment: onCreate fragment: 2130837589 D/PageFragment: onAttach fragment D/PageFragment: onCreate fragment: 2130837591 D/PreviewActivity: onSetImage a D/PageFragment: onCreateView fragment: 2130837590 D/PreviewActivity: onSetImage a D/PageFragment: onCreateView fragment: 2130837589 D/PreviewActivity: onSetImage a D/PageFragment: onCreateView fragment: 2130837591 Code from the fragment:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pageNumber = getArguments().getInt(ARGUMENT_PAGE_NUMBER); Log.d(TAG, "onCreate fragment: " + pageNumber); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_view_pager, null); ImageView resultView = (ImageView) view.findViewById(R.id.result_image); resultView.setImageResource(pageNumber); final Bitmap bitmap = ((BitmapDrawable) resultView.getDrawable()).getBitmap(); eventListener.onSetImage(bitmap, pageNumber); // pass bitmap to parent ActivityBug Log.d(TAG, "onCreateView fragment: " + pageNumber); return view; } When we will do the swipe right-left in this activation, each time I will receive either the next page image or the previous one, because it will always be overwritten, how can I always get the current image of the page, then to transfer it to the parent activation?