Nativescript: Navigating in Frame loaded event crashes the app after resume

Created on 4 Jul 2018  路  5Comments  路  Source: NativeScript/NativeScript

Tell us about the problem

I'm trying to navigate in loaded event of the main frame (because I'm doing a login check in it), but when I call navigate, the app crashes.

Which platform(s) does your issue occur on?

Android, but not tested on iOS

Please provide the following version numbers that your issue occurs with:

  • CLI: 4.1.1
  • Cross-platform modules: 4.1.0
  • Runtime(s): 4.1.3
  • Plugin(s):
"dependencies": {
  "nativescript-theme-core": "~1.0.4",
  "tns-core-modules": "~4.1.0"
}

Please tell us how to recreate the issue in as much detail as possible.

Preview App

Run the app in the NativeScript Preview app and then pause the app using activity menu. Then try to resume it.

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

The example code is in the preview app


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

backlog bug android low

All 5 comments

Hi @reinaldorauch,
Thank you for the provided project.
I tested it on my side, however, the project was built correctly and the navigation was executed as expected. I checked the case on Android API level 22, 23, 27 and device with iOS 11.4.

Can you provide more info about the device or emulator, which you are using? Also, can you check, whether something more should be added in the sample project?

Hello, I'm using a Motorola Moto G 1st gen running lineage os, with the lastest api level. I runned it also in a moto g4 with android 7.1.1

Here is a gif demoing the crash:
demo

I'm sure that's it with dependencies. Maybe I was not clear describing how to reproduce the crash?

Hi @reinaldorauch,
I was able to recreate the same error on Android API level 19. Regarding that, I will mark this as a bug. You can keep track of the issue for further info.

Meanwhile, I would suggest defining create method as it is shown below in app.js file. With its help, you can make the needed validations and then navigate to the needed page.

var application = require("application");
var frameModule = require("ui/frame");
application.run({create: function(){
    let test = true;
    const rootFrame = new frameModule.Frame();
    if(test){
        rootFrame.navigate("main")
    }
    else{
        rootFrame.navigate("page2")
    }

    return rootFrame;
}});

For further help, you can review the attached sample project.

Archive.zip

Also, bear in mind that using the loaded event for doing login check is not the right approach. The loaded event will be executed whenever you resume the app from the suspend mode. I am assuming that you need to make those checks only on the first start of the app. Regarding that, the above-described case with the create method will be a possible option to implement your custom validation functionality. You can also check this image, which can help in understanding, how the application events work on Android.

Let me know if I am missing something or your case is different.

I checked the minSdkVersion in Android Manifest and is 17. Maybe this is causing the bug? But using a default project created by tns create does not ask about the api level, if I am not wrong.

Anyways, thanks for the help o/

Hi @reinaldorauch,
The minimum supported API level for Android is 17. This is the reason for setting up the minSdkVersion to version 17. Regarding that, the minSdkVersion should not cause this kind of error. We will investigate further the case and will provide more info.

Was this page helpful?
0 / 5 - 0 ratings