iOS application restarts when resuming from the background

208 views
Skip to first unread message

State Thirteen

unread,
Oct 29, 2013, 8:56:06 AM10/29/13
to codenameone...@googlegroups.com
Hi,

When application resumed from the background it restarts. 
Should I use some events to save and resume application state?

Francis Perreault

unread,
Oct 29, 2013, 1:03:41 PM10/29/13
to codenameone...@googlegroups.com
Search this forum for the "ios.application_exits" flag, I'm pretty sure this is what you're looking for.

Francis

State Thirteen

unread,
Oct 29, 2013, 1:08:51 PM10/29/13
to codenameone...@googlegroups.com
Francis,

Found it. Thank you.

State Thirteen

unread,
Oct 30, 2013, 12:18:21 PM10/30/13
to codenameone...@googlegroups.com
I set the ios.application_exits=false in building hints but application still exits.
I don't have background activities and switch backround->resume in a second but still having restarts.
What  else I should check?

Shai Almog

unread,
Oct 30, 2013, 1:51:54 PM10/30/13
to codenameone...@googlegroups.com
iOS doesn't allow background execution, if your application has background threads that do stuff after stop() is invoked it will be killed by the system in 10 seconds.
There are special cases based on use cases, I can get into those if you first explain what you are trying to do.

twf...@gmail.com

unread,
Oct 30, 2013, 1:59:40 PM10/30/13
to codenameone...@googlegroups.com
Shai,

Scenario. Form with static MultiButtons - app home screen. Click on the button open a Form with container filled with MultiButtons using data from the ConnectionRequest in PostResponse method.
After second form has been filled with buttons I push Home button on the iOS device. Application goes to the background. Run application again and see app home screen with the first Form.

Shai Almog

unread,
Oct 31, 2013, 1:36:55 AM10/31/13
to codenameone...@googlegroups.com, twf...@gmail.com
This is not what I meant.

Did you modify your main class in any way? Is this a GUI builder or handcoded application.
If the latter did you remove the code that we generate where we save the current form on stop and restore it on start? Did you modify the code to ignore that logic?

twf...@gmail.com

unread,
Oct 31, 2013, 2:46:45 AM10/31/13
to codenameone...@googlegroups.com, twf...@gmail.com

I think I didn't modify anything in internal cn1 logic. All my code in StateMachine class. The application is partly handcoded. I have sort of templates in GUI which I fill with components in code.

I didn't touch StateMachineBase class and have an empty constructor in StateMachine.

public StateMachine(String resFile) {
super(resFile);
// do not modify, write code in initVars and initialize class members
// there,
// the constructor might be invoked too late due to race conditions that
// might occur
}

And in MyApplication class I have this code

public class MyApplication {
   
    private Form current;

    public void init(Object context) {
    }

    public void start() {
        if(current != null){
            current.show();
            return;
        }
        new StateMachine("/theme");        
    }

    public void stop() {
        current = Display.getInstance().getCurrent();
    }
    
    public void destroy() {
    }
}

четверг, 31 октября 2013 г., 9:36:55 UTC+4 пользователь Shai Almog написал:

Shai Almog

unread,
Oct 31, 2013, 3:32:02 PM10/31/13
to codenameone...@googlegroups.com, twf...@gmail.com
Odd, this should "just work".
You aren't resuming the app after running other apps by any chance?
If another app takes up RAM or CPU your app might be killed to provide additional RAM.
If you just exit the app and return this should work as expected, if you run other apps then this depends on the memory required by the other apps.

State Thirteen

unread,
Oct 31, 2013, 3:45:55 PM10/31/13
to codenameone...@googlegroups.com, twf...@gmail.com
Yes. I just exit and return immediately. Could it be connected with recent Eclipse plugin update? 
Is this setting sent to server by a plugin?

Shai Almog

unread,
Oct 31, 2013, 4:08:27 PM10/31/13
to codenameone...@googlegroups.com, twf...@gmail.com
Assuming you have application exits set to false then it shouldn't be related to eclipse or the client side in any way. If you create a hello world with 2 forms does that work for you as expected?

State Thirteen

unread,
Oct 31, 2013, 4:09:30 PM10/31/13
to codenameone...@googlegroups.com, twf...@gmail.com
Good idea. I'll try this.

State Thirteen

unread,
Nov 1, 2013, 2:20:28 AM11/1/13
to codenameone...@googlegroups.com, twf...@gmail.com
I have created test project with two forms and it's not working too.
Then I try one of your demos - SocialBoo and it works. 
So I guess there is part of the code missing in the new project created by the plugin. What should I check?

State Thirteen

unread,
Nov 1, 2013, 2:52:38 AM11/1/13
to codenameone...@googlegroups.com, twf...@gmail.com
Sorry, SocialBoo doesn't work either. It restarts from Loading screen.
I have tried Chrome demo - same thing. 

State Thirteen

unread,
Nov 1, 2013, 2:59:22 AM11/1/13
to codenameone...@googlegroups.com, twf...@gmail.com
Also double click on Home button shows these application as a background app.
So this means that OS doesn't kill them I guess. They just restarts when resuming for some reason.

Shai Almog

unread,
Nov 1, 2013, 3:25:23 AM11/1/13
to codenameone...@googlegroups.com, twf...@gmail.com
I think we might have a regression, I'll have a look.

Shai Almog

unread,
Nov 2, 2013, 4:49:48 AM11/2/13
to codenameone...@googlegroups.com, twf...@gmail.com
I tested this with some applications and this worked for me as expected, social boo is an old demo so its lifecycle code isn't up to date (same applies for the kitchen sink). Try the cn1pocker demo or a hello world application.

State Thirteen

unread,
Nov 2, 2013, 5:01:36 AM11/2/13
to codenameone...@googlegroups.com, twf...@gmail.com
Ok. I'll try the cn1pocker. It's strange. Even pure Hello World doesn't work on my device.
Could it be the issue with jailbroken devices? I tested it on ipad. 
Is it building server specific settings or I can check the code or some project settings by myself?

суббота, 2 ноября 2013 г., 12:49:48 UTC+4 пользователь Shai Almog написал:

Shai Almog

unread,
Nov 2, 2013, 1:20:04 PM11/2/13
to codenameone...@googlegroups.com, twf...@gmail.com
Should work just fine as long as your main class has the start method that restores the current form.
Make sure to define the exits false in the hello world too, it should work.
Reply all
Reply to author
Forward
0 new messages