K
K
kirawa2018-09-25 08:44:36
Android
kirawa, 2018-09-25 08:44:36

How to save the entire stack of fragments within an activity?

There is MainActivity, where a fragment of the initial state of the application is created in onCreate.

@Override
    protected void onCreate(Bundle savedInstanceState) {
     fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        getFragmentManager().beginTransaction()
                .replace(R.id.contentMain, new StatisticsFragment())
                .commit();
}

Also, in MainActivity, many more different fragments are created from NavigationDrawer, etc.
There is a problem when, while the application is running, the user stops at TasksFragment and they called him or he went to another application, then when switching back to the application, I catch an error when initializing the interface
class TasksFragment{
mCallbacks = (ICallbacks)getFragmentManager().findFragmentById(R.id.contentMain);
}

java.lang.ClassCastException: com.fragments.StatisticsFragment cannot be cast to com.fragments.TasksFragment$Callbacks
at com.fragments.TasksFragment.onCreateView(TasksFragment.java:135
) .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2018-09-25
@zagayevskiy

It clearly tells you that the fragment that you added does not implement the interface you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question