I couldn’t catch this problem personally, but there are a lot of such errors on Firebase Crashlytics
I tried all the answers with StackOverflow but nothing helped
My R.layout.activity_main
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/main_graph"/>
My navigation/main_graph
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tols"
xmlns:tools2="http://schemas.android.com/tools"
android:id="@+id/main_graph"
app:startDestination="@id/ordersFragment">
<fragment
android:id="@+id/ordersFragment"
android:name="com.app.package.ui.orders.view.OrdersFragment"
android:label="@string/menu_orders"
tools:layout="@layout/fragment_orders">
<action
android:id="@+id/action_ordersFragment_to_orderFragment"
app:destination="@id/orderFragment" />
<action
android:id="@+id/action_ordersFragment_to_problemFragment"
app:destination="@id/problemFragment" />
<action
android:id="@+id/action_ordersFragment_to_settingsFragment"
app:destination="@id/settingsFragment" />
</fragment>
<fragment
android:id="@+id/problemFragment"
android:name="com.app.package.ui.problem.ProblemFragment"
android:label="@string/menu_problems" />
<fragment
android:id="@+id/orderFragment"
android:name="com.app.package.ui.order.view.OrderFragment"
android:label="OrderFragment">
<action
android:id="@+id/action_orderFragment_to_compositionFragment"
app:destination="@id/compositionFragment" />
<action
android:id="@+id/action_orderFragment_to_selectCheckDialog"
app:destination="@id/selectCheckDialog" />
</fragment>
<fragment
android:id="@+id/compositionFragment"
android:name="com.app.package.ui.composition.CompositionFragment"
android:label="fragment_composition"
tools2:layout="@layout/fragment_composition" />
<fragment
android:id="@+id/settingsFragment"
android:name="com.app.package.ui.settings.SettingsFragment"
android:label="fragment_settings"
tools2:layout="@layout/fragment_settings" />
<fragment
android:id="@+id/selectCheckDialog"
android:name="com.app.package.ui.order.view.SelectCheckDialog"
android:label="dialog_select_check"
tools2:layout="@layout/dialog_select_check" />
</navigation>
My gradle
implementation 'androidx.navigation:navigation-fragment:2.2.0'
implementation 'androidx.navigation:navigation-ui:2.2.0'
I tried different solutions but nothing helped. Judging by Firebase Crashlytics 963 crash in 342 users.
I had the same issue.
First of all, what is the source of this issue? If the app remains in the background for a while android will destroy the activities that are in the back stack. So here are some possible steps:
You can reproduce it easier if you check the "Don't keep activities" option in "Developer Option"
Possible fix: Replace fragment
tag from activity_main with FragmentContainerView
but at least for me this generates other issues.
Encountered this when tried to rotate the phone, while using the application.
This happened to me because I was using Fragment
transactions in onCreate
, even though nav_graph.xml
handles that for us.
I just changed:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.replace(R.id.container, MainFragment.newInstance())
.commitNow()
}
}
to:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With