Repository navigation
Closed
Labels
Description
Not sure if related to #6199 (not using tabs), but I am having a serious issue where the app crashes after it comes back from being in the background: The specified child already has a parent. You must call removeView() on the child's parent first.
The full exception is below.
System.err: java.lang.RuntimeException: Unable to resume activity {com.abhayastudios.myapp/com.tns.NativeScriptActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
System.err: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3788)
System.err: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3828)
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1746)
System.err: at android.os.Handler.dispatchMessage(Handler.java:105)
System.err: at android.os.Looper.loop(Looper.java:164)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6938)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
System.err: Caused by: 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:5122)
System.err: at android.view.ViewGroup.addView(ViewGroup.java:4953)
System.err: at android.view.ViewGroup.addView(ViewGroup.java:4893)
System.err: at android.view.ViewGroup.addView(ViewGroup.java:4866)
System.err: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1425)
System.err: at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
System.err: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
System.err: at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
System.err: at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
System.err: at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
System.err: at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
System.err: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
System.err: at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:379)
System.err: at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:461)
System.err: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1361)
System.err: at android.app.Activity.performResume(Activity.java:7353)
System.err: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3763)
System.err: ... 8 more
Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
- CLI:
4.2 - Cross-platform modules:
4.3.0-2018-08-17-04 - Runtime(s):
4.2 - Plugin(s): (look for the version number in the
package.jsonfile of your
project)
Activity
tsonevn commentedon Aug 21, 2018
HI @abhayastudios,
Can you provide sample project or at least some code snippets, that can help in recreating the issue on our side?
abhayastudios commentedon Aug 21, 2018
@tsonevn sorry for not proving a sample earlier, I was still trying to isolate the problem to try to find out during which commit it started to happen and I thought maybe the stack trace would be somehow meaningful to you.
Anyway, in the meantime I was able to isolate the issue to
tns-core-modules@next(currently4.3.0-2018-08-17-04). I will update here later today once I have minimal sample showing the issue.[-]NS 4.2 crash on app resume: The specified child already has a parent.[/-][+]Crash on app resume: The specified child already has a parent.[/+]abhayastudios commentedon Aug 22, 2018
@tsonevn it took me a couple of hours to take my "big app" and do elimination until I found the issue, but I was able to reproduce it in an almost clean demo project.
If you run it you will get to a page with a button and if you suspend the app and return, you will get a white page and after a while you will get the error above in this issue (if you run
tns debugat least). As I wrote above, the issue only occurs on Android and seems to be intns-core-modules@nextwhereas withtns-core-modules@4.2it is working fine.It seems that the problem is with nesting of the
page-router-outlet. If you look at theapp.routing.tsit will now look like below wherePageRouterComponentcontains apage-router-outlet(so nested in the one fromAppComponent):If I comment out the
PageRouterComponentlike below, then the app will behave correctly even when getting back from suspend:You may ask why I need this nested
page-router-outleton top of the one from theAppComponent, but in my real app the routing is of course more complex and I am first landing in a login page and am then navigating away to thePageRouterComponentwhich has a nested component with arouter-outletthat I don't ever want to return in this session.I know there were some changes in NS 4.0/4.1 around frames/routing, but like I said up until 4.2 it was working fine. Let me know if I need to explain more or if the issue I am seeing here is new expected behavior for 4.3 and I should change my routing.
Thanks!
tsonevn commentedon Aug 23, 2018
Hi @abhayastudios,
Thank you for the provided project.
I tested it on my side, however, was unable to recreate the problem. I suspended the app and after resuming everything seems to work as expected. Are there any specific steps, which should be followed while resuming the app.
abhayastudios commentedon Aug 23, 2018
Hi @tsonevn no nothing special. I tried again now by removing the old project, downloading from my github and building from scratch. I then open the app, I will see the button, suspend the app (I put my phone in sleep mode) then when I return to the app it immediately crashes and shows a blank screen.
Trying to think what else may influence the build... The version of
tnsI am using is4.2.2.abhayastudios commentedon Aug 28, 2018
@tsonevn still happening with the latest
tns-core-modules@4.3.0-2018-08-28-01. Any advice? Were you still not able to reproduce? Can you maybe ask someone else to try to reproduce?NickIliev commentedon Aug 30, 2018
@abhayastudios In the demo project you are bootstrapping the
AppComponentwhich has apage-router-outletwhich navigates in ngOnInit todashboardand then you are usingpage-router.componentwhich has again apage-router-outletwhich is using the very same app routing table ... why this structure and simply using the main page-router-outlet from AppComponent?NickIliev commentedon Aug 30, 2018
Nested page-router-outlet will be supported via this feature - closing as related to the linked feature
abhayastudios commentedon Aug 30, 2018
@NickIliev yeah like I wrote above my real app is more complex that the demo project and I needed this nested
page-router-ouletto make it work (before 4.1) , but I had another go at it yesterday and now it seems that in 4.2/4.3 at least I don't need the nestedpage-router-ouletanymore (probably since changes in 4.1) so my issue now is solved.However, I think that the app should still not crash when this does occur, so it's good that supporting nested outlets is in the works.
Thanks!
cerireyhan commentedon Nov 29, 2018
I still have this bug. The app crashes when I open the app from background notification and try to navigate. It can be fixed by navigating inside timeout(0 seconds is enough...) but its just an ugly workaround.
manoldonev commentedon Nov 29, 2018
@cerireyhan can you confirm you are using the latest version of tns-core-modules@5.0.5?
cerireyhan commentedon Nov 29, 2018
@manoldonev Yes, I'm using tns-core-modules 5.0.5, nativescript-angular: 7.0.2 and tns-android: 5.0.0
manoldonev commentedon Nov 30, 2018
@cerireyhan can you open a new issue for your specific use case (playground project or steps to reproduce would be useful) so we can investigate and address the problem?
nudiref commentedon Dec 13, 2018
i have this bug after upgrading to NativeScript 5 as well. was anyone able to solve it?
here is my configuration:
nativescript: 5.1.0
tns-core-modules: next ("^5.2.0-next-2018-12-13-170345-02")
tns-android: next ("5.2.0-2018-12-13-170001-01")
scenario:
navigate to a page when app resumes from background.
following code in app.js produces the problem:
var frameModule = require('ui/frame');
application.on(application.resumeEvent, function (context) {
frameModule.topmost().navigate('./views/home/home');
});
error:
An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to resume activity {com.A2ZFieldServices.FieldCompass/com.tns.NativeScriptActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
manoldonev commentedon Dec 14, 2018
@nudiref I was able to reproduce the problem you are describing and logged it as a new issue #6708 -- we will continue the discussion / investigation there.
manoldonev commentedon Dec 14, 2018
Locking this conversation as the original problem is now addressed. Should you experience a new manifestation of the same exception, please open a separate issue with steps to reproduce / sample project / Playground project.
Thanks!