3

I have a fragment with setRetainInstance(true) in onCreate() e.g.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    if (mlist == null)
        mlist = new ArrayList<>();
    isLoading = true;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_grid_view, container, false);

    gridView = (GridView) view.findViewById(R.id.gridview);
    onEmptyView = (TextView) view.findViewById(R.id.emptyText);
    progressBar = (ProgressBar) view.findViewById(R.id.progressBar);

    setNewAdapter();

    if (DEBUG) Log.i(TAG, "Gridview populated");
    gridView.setOnItemClickListener(this);
    gridView.setOnItemLongClickListener(this);
    gridView.setEmptyView(onEmptyView);
    registerForContextMenu(gridView);
    return view;
}

In Activity I am saving fragment using getSupportFragmentManager().putFragment(bundle, tag) and getSupportFragmentManager().getFragment(bundle, tag)

Now when I enable "Don't keep activities" option in Developer Option state of fragment is maintained but views that I am initializing in onCreateView() are destroyed. HELP!!!

Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
Amol Desai
  • 872
  • 1
  • 9
  • 17
  • Possible duplicate of [Once for all, how to correctly save instance state of Fragments in back stack?](http://stackoverflow.com/questions/15313598/once-for-all-how-to-correctly-save-instance-state-of-fragments-in-back-stack) – Andrea Lazzarotto Aug 18 '16 at 16:11

0 Answers0