Вроде так и получилось)
В MainActivity:
pagerAdapter = new MainPagerAdapter(this);
pagerAdapter.setData(fragment1Container);
В MainPagerAdapter:
public class MainPagerAdapter extends FragmentStateAdapter
{
private Fragment1Container fragment1Container;
private Fragment2Container fragment2Container;
public void setData(Fragment1Container container)
{
f ragment1Container = container;
}
public void setData(Fragment2Container container)
{
fragment2Container = container;
}
@NonNull
@Override
public Fragment createFragment(int position)
{
switch (position)
{
case 0:
Fragment1 fragment1 = new Fragment1();
Bundle bundle = new Bundle();
Gson gson = new Gson();
bundle.putString("fragment1Container", gson.toJson(fragment1Container));
fragment1.setArguments(bundle);
return fragment1;
case 1:...
В Fragment1:
private Fragment1Container fragment1Container;
if (bundle != null)
{
Gson gson = new Gson();
String jsonString = bundle.getString("fragment1Container");
Type entityType = new TypeToken<Fragment1Container>(){}.getType();
fragment1Container = gson.fromJson(jsonString , entityType );
}