NativeScript icon indicating copy to clipboard operation
NativeScript copied to clipboard

Regression: Back button breaks app on clearHistory: true (android)

Open Daxito opened this issue 10 years ago • 23 comments

So seems like if you have this scenario, the back button breaks the App, it can't navigate back any more, and it just crashes.

  1. Create an app using the new version 1.6.0
  2. Create Page1, Page2 and Page3
  3. Make Page1 you initial page, and add a button to navigate to Page2 like: var nav = { moduleName: "./Page2", backstackVisible: true, clearHistory: true }; frame.topmost().navigate(nav)
  4. In Page2, add another button to navigate to Page3, like: exports.toPage3 = function(){ frame.topmost().navigate("./Page3") }
  5. Once in Page3, try to navigate back using the "Back" button on your device, it just crashes, or you get a blank screen sometimes, I also attached a sample app if you want to use it. sampleapp.zip .

Daxito avatar Feb 17 '16 20:02 Daxito

Wow, so am I the only one with this issue? I attached a sample with the issue, you can just run it and you will see. Using brand new project....

Daxito avatar Feb 18 '16 17:02 Daxito

@Daxito -- patience is a virtue. :grinning: v1.6 was a big release; they are dealing with not only their normal day to day stuff, but dealing with an typical issue load from a new release. It will be checked out.

NathanaelA avatar Feb 18 '16 17:02 NathanaelA

I know, after a release I myself face issues, I was just pinging :-)

Daxito avatar Feb 18 '16 18:02 Daxito

@Daxito - If it makes you feel any better, I just tested your app (which is very much appreciated by everyone that you provided a sample and a sample without the runtimes, Woohoo!!!!) and it does indeed have some weird behavior and can crash. Not a good thing.

Test 1:

  Nav Main Page to Page 1
  Page 1 -> Page 2
  Hit Back Button   ----   Blank Screen  (Should be Page 1)

test 2:

Main Page -> Page 1
Page 1 -> Page 2
Page 2 -> Page 3
Back Button --- Crashes

NathanaelA avatar Feb 18 '16 18:02 NathanaelA

Yes, easy to test. I know it is dificult to find and issue without some sample, I try to add a sample when possible. Thank you @NathanaelA

Daxito avatar Feb 18 '16 18:02 Daxito

@enchev @valentinstoychev @atanasovg - I'm not sure who needs to see this bug; but this is a very NASTY bug. It causes crashes to show up elsewhere in the code base... I just spent another two hours helping another developer figure out why his app was crashing when all he was doing was navigating to another page. Literally the button only had the frame.topmost.navigate() in it.

The second crashing situation is as such:

In this specific case you must actually be running the debugger, weird I know -- if you aren't running the debugger the timing must be slightly off or something. (i.e. tns debug android)

  1. Login Page -> Login uses "clearHistory: true" to navigate to menu.
  2. Menu -> Click a button which calls: frame.topmost.navigate('someotherpage');
    --- Crashs with:
com.tns.NativeScriptException: No weak reference found. Attempt to use cleared object reference id=-1193383688
               at com.tns.Platform.getJavaObjectByID(Platform.java:633)
               at com.tns.Platform.callJSMethodNative(Native Method)
               at com.tns.Platform.dispatchCallJSMethodNative(Platform.java:812)
               at com.tns.Platform.callJSMethod(Platform.java:711)
               at com.tns.Platform.callJSMethod(Platform.java:690)
               at com.tns.Platform.callJSMethod(Platform.java:680)
               at com.tns.gen.android.app.Fragment_ftns_modules_ui_frame_frame_l34_c42__.onDestroyView(android.app.Fragment.java)
               at android.app.Fragment.performDestroyView(Fragment.java:1898)
               at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:954)
               at android.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1167)
               at android.app.BackStackRecord.run(BackStackRecord.java:641)
               at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
               at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
               at android.os.Handler.handle

It took me a while; but I was able to trace down exactly where it was crashing in the JS code.
view.android.js, line (https://github.com/NativeScript/NativeScript/blob/master/ui/core/view.android.ts#L422) (Line 351 in the 1.6)

this._nativeView.removeView(child._nativeView);

The menu template was a very simple template:

<Page actionBarHidden="true">
  <StackLayout>
  <Img 1>
  <GridLayout ...>
     <Img><Img>
     <Img><Img>
   </GridLayout>
</StackLayout>
</Page>

It would crash when it was the child was <Img 1> with the above error.

NathanaelA avatar Feb 19 '16 06:02 NathanaelA

Hey @slavchev, @hshristov can you help here?

enchev avatar Feb 19 '16 14:02 enchev

I'm also having this issue, any solutions so far?

I have tried to go back to 1.5.2 but without much success since it now displays some other errors that did not happen before.

Louroj avatar Feb 24 '16 10:02 Louroj

Can we have this before 1.7.0? I have the same issue

tiagordc avatar Feb 24 '16 16:02 tiagordc

+1

Also affected by this issue. In my app logging out takes you back to the login page and clears history. After logging back and navigating around the first use of the back button crashes the app.

Would be awesome to have this fixed before 1.7.

firecube avatar Feb 24 '16 23:02 firecube

@Daxito, would you please, change the title to something a little bit shorter, so that it gets fine in the release notes?

For example:

Regression: Back button breaks app on clearHistory: true (android)

ErjanGavalji avatar Feb 25 '16 09:02 ErjanGavalji

I'm also getting this same crash. Thing is I'm not even clearing the back history. I think I have a even more weird case:

I navigate to page2 with

let navigationEntry = {
        moduleName : "select",
        context : {
            deferred: deferred
        }
};
topmost().navigate(navigationEntry);

And on the select page I have a button which calls topmost().goBack();. Sometimes, if I stay long enough on the select page I can't click the button anymore (It doesn't cause the app to go back to home). If I press the physical back button on Android, the app closes (literally and some seconds after it reopens with the error) and the error

java.lang.RuntimeException: Unable to destroy activity {org.nativescript.quedia/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: No weak reference found. Attempt to use cleared object reference id=-1216981224
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3739)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3757)
at android.app.ActivityThread.access$1500(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375)

appears out of nowhere. Is this somehow related to this bug?

vjoao avatar Feb 27 '16 16:02 vjoao

This bug hits me as well (v1.6.2) which is very annoying, please create a release with the fix asap if you want/can!

GerjanOnline avatar Mar 11 '16 11:03 GerjanOnline

#1701 is another case of weird navigation crashing.

NathanaelA avatar Mar 15 '16 14:03 NathanaelA

I added clearHistory: true to one of my navigations and during navigation app crashed with error

android.content.res.Resources$NotFoundException: Resource ID #0xffffffec at android.content.res.Resources.getValue(Resources.java:1163) at android.content.res.Resources.loadXmlResourceParser(Resources.java:2349) at android.content.res.Resources.getAnimation(Resources.java:1003) at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:71) at android.app.FragmentManagerImpl.loadAnimator(FragmentManager.java:744) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:959) at android.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1168) at android.app.BackStackRecord.run(BackStackRecord.java:641) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1450) at android.app.FragmentManagerImpl$1.run(FragmentManager.java:444) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5118) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606) at dalvik.system.NativeStart.main(Native Method)

Crashed on 1.7.1, everything works fine on 2.0.0-2016-04-27-549.

orsag avatar Apr 29 '16 09:04 orsag

@orsag Did you remember what fixed it? I can't reproduce it on my side but I've got a whole bunch of sentry errors poppin with the very same stack trace on production

jeremypele avatar Jan 22 '18 22:01 jeremypele

System.err: android.content.res.Resources$NotFoundException: Resource ID #0xffffffec
System.err:     at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:215)
System.err:     at android.content.res.Resources.loadXmlResourceParser(Resources.java:2134)
System.err:     at android.content.res.Resources.getAnimation(Resources.java:1167)
System.err:     at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:125)
System.err:     at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:106)
System.err:     at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:91)
System.err:     at android.app.FragmentManagerImpl.loadAnimator(FragmentManager.java:1089)
System.err:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1368)
System.err:     at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1557)
System.err:     at android.app.BackStackRecord.executeOps(BackStackRecord.java:802)
System.err:     at android.app.FragmentManagerImpl.executeOps(FragmentManager.java:2386)
System.err:     at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2181)
System.err:     at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2136)
System.err:     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2043)
System.err:     at android.app.FragmentManagerImpl$1.run(FragmentManager.java:719)
System.err:     at android.os.Handler.handleCallback(Handler.java:790)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
System.err:     at android.os.Looper.loop(Looper.java:164)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6494)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

@jeremypele - I have same/similar issue in 3.4.1. Happened once randomly while developing, can't reproduce, and it is happening in the wild.

john-e-riordan avatar Feb 14 '18 00:02 john-e-riordan

And this one which has a slightly different trace, but...

System.err: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
System.err: 	at android.view.ViewGroup.addViewInner(ViewGroup.java:4937)
System.err: 	at android.view.ViewGroup.addView(ViewGroup.java:4768)
System.err: 	at android.view.ViewGroup.addView(ViewGroup.java:4708)
System.err: 	at android.view.ViewGroup.addView(ViewGroup.java:4681)
System.err: 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1284)
System.err: 	at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1557)
System.err: 	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1618)
System.err: 	at android.app.BackStackRecord.executeOps(BackStackRecord.java:807)
System.err: 	at android.app.FragmentManagerImpl.executeOps(FragmentManager.java:2386)
System.err: 	at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2181)
System.err: 	at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2136)
System.err: 	at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2043)
System.err: 	at android.app.FragmentManagerImpl$1.run(FragmentManager.java:719)
System.err: 	at android.os.Handler.handleCallback(Handler.java:790)
System.err: 	at android.os.Handler.dispatchMessage(Handler.java:99)
System.err: 	at android.os.Looper.loop(Looper.java:164)
System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6494)
System.err: 	at java.lang.reflect.Method.invoke(Native Method)
System.err: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

john-e-riordan avatar Feb 14 '18 00:02 john-e-riordan

@jeremypele

I believe I’ve tracked this one down after a lot of painful work to reproduce it.

TLDR; When the ExtendedNavigationOptions transition property is undefined, the crashes do not occur (or at least in that case I have yet to be able to reproduce them).

On Android as of 3.4.1 there appears to be a bug/issue in NativeScript routing extensions when using a transition. It eventually crashes. The crashes are hard to reproduce. It's not clear to me what the issue is, but perhaps it seems to have something to do with calling navigate() repeatedly (and seems likely related to something down in ui/frame). In my case, I'm calling navigate() repeatedly before a prior call to navigate() resolves, but I'm not sure if that's a requirement to cause a crash.

Calling navigate() repeatedly is legit and Angular handles it well, but NativeScript provides a custom LocationStrategy to the Angular router and guessing the issue is down in that direction someplace. Like eyeballing the code and using a bit of imagination it doesn't seem far fetched that there is some issue that crops up when calling navigate() repeatedly with transition = { name: "fade" } while there are outstanding calls to navigate() that have not resolved (for what is is worth, I was able to reproduce the crash consistently/eventually (stress eventually) using the "fade" transition but didn't try with any others). Like perhaps it is getting tripped up because NSLocationStrategy is storing a single reference to the current NavigationOptions which is getting over written on each call to navigate() regardless of there being prior calls to navigate() that have yet to be resolved? But not digging into it further, that's pure reckless speculation and I know enough to know I don't know the code involved well enough to have a real clue.

There doesn't seem to be an issue on iOS, thus the ui/frame speculation.

john-e-riordan avatar Feb 14 '18 20:02 john-e-riordan

@jeremypele @john-e-riordan I just got a crash report from Filebase production app with a similar stack. I have no idea on what triggered it, as it's a production app, and I only get Java stack, no TS. If you find anything worth trying, please ping me.

Exception android.content.res.Resources$NotFoundException: Resource ID #0xffffffec android.content.res.ResourcesImpl.getValue (ResourcesImpl.java:202) android.content.res.Resources.loadXmlResourceParser (Resources.java:2968) android.content.res.Resources.getAnimation (Resources.java:2008) android.animation.AnimatorInflater.loadAnimator (AnimatorInflater.java:125) android.animation.AnimatorInflater.loadAnimator (AnimatorInflater.java:106) android.animation.AnimatorInflater.loadAnimator (AnimatorInflater.java:91) android.app.FragmentManagerImpl.loadAnimator (FragmentManager.java:827) android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1065) android.app.FragmentManagerImpl.removeFragment (FragmentManager.java:1280) android.app.BackStackRecord.run (BackStackRecord.java:766) android.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1582) android.app.FragmentManagerImpl$1.run (FragmentManager.java:483) android.os.Handler.handleCallback (Handler.java:751) android.os.Handler.dispatchMessage (Handler.java:95) android.os.Looper.loop (Looper.java:154) android.app.ActivityThread.main (ActivityThread.java:6642) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)

sserdyuk avatar Feb 19 '18 19:02 sserdyuk