Android Activity Navigation


#1

Hello there!

The navigation documentation is pretty vague when it comes to Android. I’ve been trying for hours now to figure out how to navigate to a new page on a new activity. The only documentation about this that I found is on this page:

https://github.com/NativeScript/NativeScript/blob/master/tns-core-modules/ui/frame/Readme.md

// create a new Frame instance
var frameModule = require("ui/frame");
var frame = new frameModule.Frame();
frame.navigate("newPage");

The last block of code (as shown above) shows exactly what I need. My problem is that it navigates to a new activity but it is completely empty. Anyone know a solution or a way to do it properly?

Thank you.


#2

Hey @SteveGoodtime. If you still not complete the awesome NativeScript Groceries tutorial, Please try to complete it. I am sure then you will get good idea on navigation workflows.

https://docs.nativescript.org/tutorial/chapter-2


#3

The tutorial does not mention anything about navigating to another frame. My navigation works when navigating from fragment to fragment (topmost frame) but when I try to navigate to a new frame it is blank.


#4

I’m not an expert on navigation in non-Angular apps by any means, but I have used it in the past - for instance in the Bluetooth plugin demo app: https://github.com/EddyVerbruggen/nativescript-bluetooth-demo/blob/e5481cc47230101f9abf292df1cbb9d2ba6b2d98/Bluetooth/app/main-view-model.js#L45-L55


#5

frameModule.topmost().navigate(“path”); works exactly how it should. On Android, there is two ways of navigating: Fragments and Activities. When navigating the topmost frame, it just switches fragments. What I am looking for is navigating to another frame which switches activities which is the right way of navigating on Android.


#6

Ah, I never had the need to break out of the NativeScriptActivity really. Except for of course showing stuff like camera / barcodereader activities via Intents.


#7

I completed my app using default fragment navigation but found that activity navigation is must. If you look at pure native apps, they mostly use it.


#8

Ok, maybe someone can help me here…

After trying to read the code for a while, I found the function “_navigateCore” which calls the function that starts a new activity and then creates a new fragment. So I found a piece of code that blocks the creation of a new fragment:

I then I tried to recall the function a few milliseconds later using a timer by passing the same backstackEntry which I took from “_delayedNavigationEntry”. This actually made it work but not consistently:

    var frame = new frameModule.Frame();
    frame.navigate(navigationEntry);
    setTimeout(function() {
        frame._navigateCore(frame._delayedNavigationEntry);
    }, 10);

The main problem is that it flashes a blank activity before adding the fragment/page.
The other problem is that I need to get the activity right after I call the “frame.navigate()” function by using “frame.android.activity”.

Any suggestions will help.

Thank you.