Hi,
I'm new to CN1 and trying to understand how (back) navigation works in CN1. So far, I've seen several navigation-related posts but I still miss an overview. I also see a bunch of methods like back(), showBack(), setBackDestination(), showForm() that all relate to navigation but the API documentation isn't crystal clear as to which should be used when.
I would like detailed answers to at least the following questions. How can one properly implement navigation for:
- A GUI builder-based app with complex navigation? So something like A --> B --> C ---> D --->(back) ---> B.
- A GUI builder-based app that uses forms as 'templates'? See the concrete question below for what I mean by 'templates'.
- An app that includes both GUI Builder forms and hand-coded forms? As far as I can see from the forum, there are some nuances related to this.
- An app that has a splash screen? In one of the threads, I think I saw something about splash screens being a bit of a special case.
- An app with GUI builder and/or handcoded forms that has a custom navigation management component? So I want to have my own class that manually decides what back does on every form without any help from the CN1 framework.
PS: It would be great if the Developer Guide can be extended with a section dedicated to a sufficiently detailed explanation of navigation in CN1. Going by the number of threads I've seen here on this topic, I think it will also save the CN1 team useful time currently spent on answering nearly duplicate questions.
======= Concrete Example =======
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Simulator + Android device
I have a simple application consisting of two forms, say "Main" and "Question". The "Main" form contains a "Start" button that triggers a series of questions. The "Question" form is basically a re-usable template with a content section and a "Previous" and "Next" button. Navigation using the previous and next buttons works fine. However, when I use the Back button, I get strange behavior.
More concretely, given the following navigation stack
[{}, {$title=Test, $focus=start, $name=Main}, {$title=Test, $focus=next, $name=Question}, {$title=Test, $focus=next, $name=Question}, {$title=Test, $focus=next, $name=Question}] (so Main --> Question --> Question --> Question)
- The previous button takes me to the desired state of [{}, {$title=Test, $focus=start, $name=Main}, {$title=Test, $focus=next, $name=Question}, {$title=Test, $focus=next, $name=Question}] (i.e., Main --> Question --> Question)
- However, the Back button takes me directly to Main without updating the navigation stack. I don't seem to find the correct way to make the Back button behavior match that of the Previous button in the Question form. What am I doing wrong?
The relevant code from the previous and next button action handlers in the StateMachine is as follows:
@Override
protected void onQuestion_PreviousAction(Component c, ActionEvent event) {
if (currentQuestion == null || model.getPreviousQuestion(currentQuestion) == null) {
showForm("Main", null);
} else {
currentQuestion = model.getPreviousQuestion(currentQuestion);
setBackDestination("Question");
back();
}
}
@Override
protected void onQuestion_NextAction(Component c, ActionEvent event) {
if (model.getNextQuestion(currentQuestion) == null) {
showForm("Main", null);
} else {
currentQuestion = model.getNextQuestion(currentQuestion);
showForm("Question", null);
}
}