When do showForm("myform",null) from postResponse, it flashes up then jumps back to the prev frorm

154 views
Skip to first unread message

eos

unread,
Aug 28, 2013, 1:38:34 PM8/28/13
to codenameone...@googlegroups.com
I copied the web service example on this page: http://www.codenameone.com/how-do-i.html exactly.

It works, but in my postResponse, I have showForm instead of updating a component, thusly:

 
 ConnectionRequest con = new ConnectionRequest() {
   
Hashtable json;
   
   
@Override
   
protected void postResponse(){
    name
= json.get("firstName").toString();
   
   
if (name != null && !"".equals(name)) {
   
System.out.println("about to show main form");
    showForm
("MainForm", null);
   
}
   
}
   
   
@Override
   
protected void readResponse(InputStream input) throws IOException {
   
JSONParser p = new JSONParser();
        json
= p.parse(new InputStreamReader(input));
       
System.out.println("" + json);
   
};
       
   
};
   
    con
.setPost(false);
    con
.setUrl(URL + "/login");
    con
.addArgument("user", card);
    con
.addArgument("pass", pin);
   
InfiniteProgress prog = new InfiniteProgress();
   
Dialog dlg = prog.showInifiniteBlocking();
    con
.setDisposeOnCompletion(dlg);

The problem is, it flashes up MainForm, then immediately goes back tot he login form.

If I do the ShowForm directly from the button action call, it works.

Im using side menu style if that has any bearing, and the login form (which is the initial form) has no command etc.

Any ideas?

Chen Fishbein

unread,
Aug 28, 2013, 3:51:26 PM8/28/13
to codenameone...@googlegroups.com
try to wrap the call to showForm in a callSerially

eos

unread,
Aug 28, 2013, 5:50:24 PM8/28/13
to codenameone...@googlegroups.com
It took me some time to find out how to use callSerially, but it seems to work, thanks.   What I don't get is that the post Response is executed in the EDT, so changes to the UI made there should be safe, and callSerially is supposed to be used off the EDT?

Shai Almog

unread,
Aug 29, 2013, 2:22:09 AM8/29/13
to codenameone...@googlegroups.com
What Chen suggested is a bit of a patch to send your request to the next EDT cycle this effectively allows the Sidemenu to animate and close.

If you did the connection from the side menu I'm assuming using add to queue and wait, then you blocked the side menu from closing.
I suggest not using add to queue and wait but instead using add to queue.
Also look at the sidemenu API. There are some methods there such as closeCurrentMenu(Runnable) which you can use if you are adding custom buttons to the side menu and need to close it manually (should happen automatically for commands).

eos

unread,
Aug 29, 2013, 3:41:20 AM8/29/13
to codenameone...@googlegroups.com
Hi Shai.  The initial form, i.e. the login form, has no side menu and has no commands.  It only has the textfields for user/pass and a login button.  The call to the server is initiated when they hit the login button using an action event handler.  So I don't think I'm calling it from the side menu. When I dont use the callSerially, it opens the new form, then immediately jumps back to the login form.

ein...@gmail.com

unread,
Sep 22, 2016, 8:07:59 AM9/22/16
to CodenameOne Discussions
Please show me, how it can be wrap on callSerially so that it can appear.

Shai Almog

unread,
Sep 23, 2016, 1:58:27 AM9/23/16
to CodenameOne Discussions, ein...@gmail.com
Reply all
Reply to author
Forward
0 new messages