Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NavigationBasicSample] crash #446

Closed
jaredtech opened this issue Aug 17, 2018 · 22 comments
Closed

[NavigationBasicSample] crash #446

jaredtech opened this issue Aug 17, 2018 · 22 comments

Comments

@jaredtech
Copy link

TitleScreen ---> Register ---> Match ---> InGame ---> ResultsWinner/GameOver ---> Match, then click 'Back Key' back to Register, then click SIGN UP, crash.
log:
com.example.android.navigationsample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.android.navigationsample, PID: 3184 java.lang.IllegalArgumentException: navigation destination com.example.android.navigationsample:id/action_register_to_match is unknown to this NavController at androidx.navigation.NavController.navigate(NavController.java:669) at androidx.navigation.NavController.navigate(NavController.java:628) at androidx.navigation.NavController.navigate(NavController.java:616) at com.example.android.navigationsample.Register$onCreateView$1.onClick(Register.kt:39) at android.view.View.performClick(View.java:6266) at android.view.View$PerformClick.run(View.java:24730) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:171) at android.app.ActivityThread.main(ActivityThread.java:6672) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:246) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)

就是游戏一次无论输赢,回到匹配的界面,再点击返回按钮回到登录界面,再次点登录按钮会崩溃。
原因没有找到。

英文不好,大佬看到可以帮忙翻译一下,谢谢

@ChunPangWong
Copy link

#435

@gilgoldzweig
Copy link

bug returns on 1.0.0-alpha06 ktx

java.lang.IllegalArgumentException: navigation destination com.nyx.tech.dev:id/action_home_fragment_to_calibration_fragment is unknown to this NavController
        at androidx.navigation.NavController.navigate(NavController.java:691)
        at androidx.navigation.NavController.navigate(NavController.java:648)
        at androidx.navigation.NavController.navigate(NavController.java:634)
        at androidx.navigation.NavController.navigate(NavController.java:712)
        at com.nyx.tech.fragments.home.HomeFragment.onFeatureInitiated(HomeFragment.kt:240)
        at com.nyx.tech.fragments.home.HomeFragmentPresenter$observe$1.onChanged(HomeFragmentPresenter.kt:177)
        at com.nyx.tech.fragments.home.HomeFragmentPresenter$observe$1.onChanged(HomeFragmentPresenter.kt:50)
        at android.arch.lifecycle.LiveData.considerNotify(LiveData.java:109)
        at android.arch.lifecycle.LiveData.dispatchingValue(LiveData.java:126)
        at android.arch.lifecycle.LiveData.setValue(LiveData.java:282)
        at android.arch.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33)
        at android.arch.lifecycle.LiveData$1.run(LiveData.java:87)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-14 15:23:52.527 23366-23427/com.nyx.tech.dev W/NYXApplication$onCreate: com

@tsuijten
Copy link

tsuijten commented Nov 2, 2018

I also ran into this issue. Seems to be fixed in the alpha07 release.

@badoualy
Copy link

I have a similar issue with alpha07 on my project, I'll try to reproduce on this sample.

@silvioAL
Copy link

I have the same issue with alpha07

@mikaelj
Copy link

mikaelj commented Nov 28, 2018

Me three.

@HGyllensvard
Copy link

HGyllensvard commented Dec 1, 2018

We also noticed these errors with alpha07 (Kotlin if it matters).

The root error in our case was if two navigations happened too close to one another.
Say we have Fragment A, B and C.
Somehow the application starts two navigations almost at the exact same time, like:
A navigates to B
A navigates to C

The navigation library will open fragment B, and then tries to perform the A -> C navigation, but looking at Fragment B's actions, which leads to a crash.

Once we realised this we could easily reproduce the error.

We noticed the problem in our recycler view with different items taking the user to different fragments.
One way for us to solve it was to use an Atomic boolean which is reset in OnResume and then perform a getAndSet before trying to perform the navigation.

Edit: Improved explanation

@Trumeet
Copy link

Trumeet commented Dec 2, 2018

+1 With Alpha 07

@mikaelj
Copy link

mikaelj commented Dec 6, 2018

Anyone tried alpha08 yet? Out just now.

@keluokeda
Copy link

+1 With Alpha 07

@lcszc
Copy link

lcszc commented Dec 13, 2018

Same happening in alpha-08 and alpha-09.

@kinnrot
Copy link

kinnrot commented Jan 9, 2019

I also encountered this issue, currently patching it with mutable live data, post value, which just pushes the navigation call to the end of the event loop, which is similar to Handler().post. seems to work fine for now.

@cedrtang
Copy link

Had the same problem in alpha-09. I used a global action to pop back to Root (self) then doing any navigation on my graph would trigger the issue.

I solved it by setting my Activity android:launchMode="singleTop"in Manifest and instead of pop to Root, I pop to my Home Fragment directly.

@kinnrot
Copy link

kinnrot commented Jan 11, 2019

@cedrtang can you share before and after code ?

@cedrtang
Copy link

@kinnrot Sure.

Manifest.xml
Before
<activity android:name=".ui.activities.MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar">

After:
<activity android:name=".ui.activities.MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar" android:launchMode="singleTop">

nav_graph.xml
Before:
<action android:id="@+id/action_nav_graph_pop" app:popUpTo="@id/nav_graph" />

After:
<action android:id="@+id/action_nav_graph_pop" app:popUpTo="@id/homeFragment" />

My navigation flow works all the way through a particular flow then back home and can do it again. Up and back navigation works as well.

I use a mix of different methods to manage my navigation:
Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(HomeFragmentDirections.actionHomeFragmentToLoginFragment(error, response.data));
binding.finishBtn.setOnClickListener(v -> Navigation.findNavController(v).navigate(R.id.action_nav_graph_pop));
binding.anotherCardBtn.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_nav_graph_pop));

Hope it helps

@lcszc
Copy link

lcszc commented Jan 25, 2019

Crash still happening in alpha10 and alpha-11 even after a lot of bug fixes. :>

@Dwite
Copy link

Dwite commented Jan 30, 2019

Any ideas how to fix it ?

@yosim199
Copy link

yosim199 commented Feb 5, 2019

Same here on alpha-11

@korydondzila
Copy link

My nav actions will popup to the nav, with the destination as the home fragment. Here is an example, HistoryCalendarFragment can be reached from the WeeklyFragment. This action is used when clicking on a specific week in a calendar to go to that week in the WeeklyFragment. I'm not sure if maybe this the combined use of destination and popUpTo with Inclusive that solves the issue, but I do not get this crash.

<action android:id="@+id/action_historyCalendarFragment_to_weeklyFragment" app:destination="@+id/weeklyFragment" app:popUpTo="@+id/nav_duty_hours" app:popUpToInclusive="true" />

findNavController().navigate( HistoryCalendarFragmentDirections.actionHistoryCalendarFragmentToWeeklyFragment( selectedWeek.toString() ) )

Though I have had this crash when doing something like this:
findNavController().popBackStack(R.id.nav_evaluations, false)
In this instance the current fragment is two down from the root and want to get back to the root (i.e. like clicking home/back twice). This issue was fixed by instead doing this:
findNavController().popBackStack(R.id.evaluationsFragment, false)
Where instead of specifying the nav itself I specify the fragment.

As @cedrtang mentioned this seems to be an issue with popping to the root directly. I do not have SingleTop set in the Manifest.

@ianhanniballake
Copy link
Contributor

Please file issues with the Navigation library on the issue tracker with a sample project that reproduces your issue.

@Keldmar
Copy link

Keldmar commented Mar 16, 2020

I wrote this extensions

fun Fragment.navigateAction(action: NavDirections) {
    val navController = this.findNavController()
    if (navController.currentDestination?.getAction(action.actionId) == null) {
        return
    } else {
        navController.navigate(action)
    }
}

@ghost
Copy link

ghost commented Sep 20, 2020

I,m fixed bug.
Problem DONT UI thread...

This is working

activity?.runOnUiThread{
                        findNavController().popBackStack()
                    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests