In my app, I have a single Activity
and multiple Fragments
. From my MainActivity
, I add my first Fragment
. From inside the first Fragment
adapter based on item click, I add the second Fragment
. And from second Activity
adapter based on item click, I add the third Fragment
.
Everything works well but on orientation change, the app crashes.
Code:
MainActivity:
if (savedInstanceState == null) {
mHomeScreenFragment = (HomeScreenFragment) getSupportFragmentManager().findFragmentById(R.id.contentFrame);
if (mHomeScreenFragment == null) {
mHomeScreenFragment = HomeScreenFragment.newInstance();
}
ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), mHomeScreenFragment, R.id.contentFrame, "HomeScreen");
}
1st Fragment adapter - on item click:
FoodListFragment foodListFragment = null;
if (foodListFragment == null) {
foodListFragment = foodListFragment.newInstance(position);
ActivityUtils.replaceFragmentToActivity(((MainActivity) view.getContext()).getSupportFragmentManager(),
foodListFragment, R.id.contentFrame, "FoodList");
}
2nd Fragment
adapter - on item click:
FoodDetailsFragment foodDetailsFragment = null;//(FoodDetailsFragment) ((MainActivity)view.getContext()).getSupportFragmentManager().findFragmentByTag("FoodDetails");
if (foodDetailsFragment == null) {
foodDetailsFragment = foodDetailsFragment.newInstance(foodListData.getUrl(),
foodListData.getName(),
foodListData.getSalePrice().getAmount(),
foodListData.getSalePrice().getCurrency());
}
ActivityUtils.replaceFragmentToActivity(((MainActivity)view.getContext()).getSupportFragmentManager(), foodDetailsFragment, R.id.contentFrame, "FoodDetails");
can some help me to tell how to properly handle orientation change in case of 1 Activity
and multiple Fragments
?
I have almost tried all the solutions on StackOverflow and other places and nothing seem to work.
Please follow android basic documentation. I hope your doubt will be cleared.
https://developer.android.com/guide/topics/resources/runtime-changes.html
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
Is it possible to put multiple multiple EXTRA_TEXT's
So I am writing an android code where there are 3 buttons:record, pause, take frameRecord button records a video, pause button pauses the video displaying in VideoView and Take frame button shows the paused frame in imageView
When debugging my app, it's currently returning a jpg file that I'm not able to see in my adb