programatically go back

49 views
Skip to first unread message

howud...@gmail.com

unread,
Aug 28, 2016, 7:48:23 PM8/28/16
to CodenameOne Discussions
Is there a way to programatically go back?  Before in the old state machine there was back().  Now with the newest framework, I cant find back().  I'm not using the new GUI builder, I am coding all by hand

ConnectionRequest r = new ConnectionRequest() {
 
protected void readResponse(InputStream input) throws IOException {
     
String sError = "This would be set by server";
 
}
 
protected void postResponse() {
     
if (!sError.equals("error")
       goBack
();
 
}
};


shyam tha

unread,
Aug 28, 2016, 9:39:46 PM8/28/16
to CodenameOne Discussions, howud...@gmail.com
Hi 
Hope the following code will help you so please check it
ConnectionRequest
 r = new ConnectionRequest(StateMachine sm ) {

  
protected void readResponse(InputStream input) throws IOException {
     
String sError = "This would be set by server";
  
}
  
protected void postResponse() {
     
if (!sError.equals("error")

      sm.back();

  
}
};

Peter Carlson

unread,
Aug 28, 2016, 10:32:37 PM8/28/16
to shyam tha, CodenameOne Discussions

ConnectionRequest does not have a constructor with StateMachine

ConnectionRequest r = new ConnectionRequest(StateMachine sm )

^^^ StateMachine cannot be resolved to a variable. 


There are no available imports for StateMachine.

shyam tha

unread,
Aug 28, 2016, 10:40:07 PM8/28/16
to CodenameOne Discussions, gshya...@gmail.com, howud...@gmail.com
Please check this and hope there will not be any problem now

public void connection(final StateMachine sm ){

ConnectionRequest r = new ConnectionRequest() {
  
protected void readResponse(InputStream input) throws IOException {
     
String sError = "This would be set by server";
  
}
  
protected void postResponse() {
     
if (!sError.equals("error")

   sm.back();

  
}
};

howud...@gmail.com

unread,
Aug 29, 2016, 10:51:23 AM8/29/16
to CodenameOne Discussions, gshya...@gmail.com, howud...@gmail.com
As far as I understand it the "StateMachine" no longer exists, or at least not in the form to which you refer.  At the minimum it does not exist in my project.
I have noticed this weird behaviour:
if I store a handle to the parent form and then call parent.showBack()
  • Just call parent.showBack() with no notification it will nicely go back to the previous form.  
  • If I call Dialog.show() first and then call parent.showBack() it doesn't go back.  
  • If I use ToastBar it does go back, but the ToastBar disappears immediately.

ConnectionRequest r = new ConnectionRequest() {
@Override
protected void readResponse(InputStream input) throws IOException {
//parse result for error
}
@Override
protected void postResponse() {
if (sResult.equals("error"))
MessageBox.OK(sErrorMsg, "Unable to Save");
else {
MessageBox.OK("Data Saved", "Info");  <<< Wont go back
MessageBox.TOAST("Data Saved");       <<< goes back but Toast disappears immediately
parent.showBack();
}
}
};

public class MessageBox {

public static void OK(String msg, String title) {
        Dialog.show(title, msg, "OK", null);
}
public static boolean OKCANCEL(String msg, String title) {
        return Dialog.show(title, msg, "OK", "Cancel");
}
public static void TOAST(String msg) {
TOAST(msg, 2500);
}
public static void TOAST(String msg, int delay) {
ToastBar.Status status = ToastBar.getInstance().createStatus();
status.setMessage(msg);
status.setExpires(delay);
status.show();
}
}




Peter

Shai Almog

unread,
Aug 30, 2016, 12:34:40 AM8/30/16
to CodenameOne Discussions, gshya...@gmail.com, howud...@gmail.com
When a Dialog is disposed it goes to the form that showed it. ToastBar is bound to a specific form so it won't work as expected either.

The solution is to showBack() and use an addShowListener before that. Within the show listener show your toastbar or dialog. This will do the back transition first and then show the dialog/toast.

howud...@gmail.com

unread,
Sep 20, 2016, 10:48:21 AM9/20/16
to CodenameOne Discussions, gshya...@gmail.com, howud...@gmail.com
ok, this solution works for an error situation.  However I am seeing similar weird behaviour when I do:
Form1 visible, click on button to show Form 2
Form2 during constructor calls toastbar and retrieves information from the server
Form2 click on "back" calls parent.showBack()
Form1 is reloaded but with toastbar visible and blocking.

Peter

howud...@gmail.com

unread,
Sep 20, 2016, 10:54:59 AM9/20/16
to CodenameOne Discussions, gshya...@gmail.com, howud...@gmail.com
well all day yesterday it was failing as described.   Today it seems to work fine...sigh

Shai Almog

unread,
Sep 21, 2016, 12:43:20 AM9/21/16
to CodenameOne Discussions, gshya...@gmail.com, howud...@gmail.com
That's a race condition.
Notice that the error methods are called off the EDT so you need to use callSerially().

howud...@gmail.com

unread,
Sep 21, 2016, 9:29:45 AM9/21/16
to CodenameOne Discussions, gshya...@gmail.com, howud...@gmail.com
I dont see any race condition, and for some reason the problem is back, but sporadic, again the steps: ( I added a few lines for clarity)
Form1 visible, click on button to show Form 2
Form2 during constructor calls toastbar and retrieves information from the server
Information is retrived no errors
Form2 click on "back" calls parent.showBack()
Form1 is reloaded but for some reason the toastbar is visible and blocking.

Shai Almog

unread,
Sep 21, 2016, 11:49:06 PM9/21/16
to CodenameOne Discussions, gshya...@gmail.com, howud...@gmail.com
Again the error callback is off the EDT. If something happens sometimes "oddly" it's a race.
Reply all
Reply to author
Forward
0 new messages