App restarting when minimized to background

7,272 views
Skip to first unread message

Nikhil

unread,
Sep 2, 2012, 1:29:12 AM9/2/12
to codenameone...@googlegroups.com
Here are my observations :


USE CASE 1

  1. Start the app and the home form shows up.
  2. Minimize the app by pressing the home button of android phone.
  3. Start the app again. The app RESTARTS.
  4. Again minimize the app and then again start it.
  5. The app restarts.
  6. On doing steps 4 and 5 couple of times (say 3 times), the app crashes. android asks me to FORCE CLOSE THE APPLICATION. 
I obviously don't want this to happen. What I want is to restore the app to the state it was before it was minimized.

USE CASE 2

  1. Follow the steps 1 to 4 from Use Case 1 above. 
  2. Now EXIT the application.
  3. The application will exit and again restart. This process happens the number of times you have accessed/started the app AFTER it was minimized.
  4. So say I start my app, minmize it and again access it (for 3 times), I'll have to exit my app (call Display.getInstance().exit) 3 times for the app to actually exit.
The expected behavior would be to exit at the first time itself.


Work Around:

I have read on these forums that the stopApp() method is called before the app goes into background. What one can do is, store the state of the program and restore it when the start() method is invoked. 

My question:
  1. Why is all this not automatically handled by CN1? I think, rather than leaving this implementation for developer it would be better if CN1 does it? Is this tough/trickly to implement?
  2. Ok, something that I have no idea how to do... How can I store the state of my program and then restore it? I have an application which has a timer task running, some forms being displayed, some arrays in the memory , some lists ,etc etc,
  3. How do I store all this(and restore)?Is there a simple way to do this?
Thanks



Chen Fishbein

unread,
Sep 2, 2012, 6:41:57 AM9/2/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com
Hi,

Regarding use case 1:

Tried to reproduce your crash without luck, if you're app gave you "force close" you can see the trace in the ddms, please have a look there to see where the exception came from.

Regarding use case 2:

This sounds very odd - I will have a look on this.


My question:
  1. Why is all this not automatically handled by CN1? I think, rather than leaving this implementation for developer it would be better if CN1 does it? Is this tough/trickly to implement?

  1. >> because there are apps that will need to handle the background/foreground callbacks.

  1. Ok, something that I have no idea how to do... How can I store the state of my program and then restore it? I have an application which has a timer task running, some forms being displayed, some arrays in the memory , some lists ,etc etc,
  1. How do I store all this(and restore)?Is there a simple way to do this?

  1. >>your app is not terminated all your objects are alive!, you simply need to store the last Form shown and show it again on start (we have updated the NB/Eclipse plugins templates to include this, update the plugin and create a new app to see how to implement this)


 

Nikhil

unread,
Sep 2, 2012, 8:21:00 AM9/2/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com
Hello Chen,
 
The USE CASE 1 issue probably does not happen with every app. It might be happening only with heavy apps? I am just guessing here. 

I have deployed my app on Google Play . its here. I got this error with the phone Samsung Galaxy DuoS. And other users of my app also have reported this kind of error.

https://play.google.com/store/apps/details?id=in.n10k.UltimateGRE 

So when I login as a developer, I see two errors in the developer console: 

They are as follows:

1)Freeze

Activity
in.n10k.UltimateGRE/.GREStub

Cause
ANR keyDispatchingTimedOut




Here is the Stack Trace:
Stack traces
v1.04
Aug 25, 2012 12:33:41 AM
OTHER

DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 MONITOR
  | group="main" sCount=1 dsCount=0 obj=0x40027190 self=0xcef8
  | sysTid=19860 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-1345006496
  at com.codename1.d.l.a((null):~-1)
  - waiting to lock <0x40526120> (a java.lang.Object) held by threadid=22 (EDT)
  at in.n10k.UltimateGRE.GREStub.onResume((null):-1)
  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
  at android.app.Activity.performResume(Activity.java:3832)
  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2131)
  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2156)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:969)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:3701)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
  at dalvik.system.NativeStart.main(Native Method)

"EDT" prio=6 tid=22 SUSPENDED
  | group="main" sCount=1 dsCount=0 obj=0x4057ae70 self=0x2c88c0
  | sysTid=20382 nice=-2 sched=0/0 cgrp=[fopen-error:2] handle=2921168
  at java.util.Vector.size(Vector.java:~934)
  at com.codename1.d.l.s((null):-1)
  at com.codename1.d.l.h((null):-1)
  at com.codename1.d.ac.run((null):-1)
  at com.codename1.impl.d.run((null):-1)

"Timer-3" prio=6 tid=24 MONITOR
  | group="main" sCount=1 dsCount=0 obj=0x40588298 self=0x378bd0
  | sysTid=20171 nice=-2 sched=0/0 cgrp=[fopen-error:2] handle=3656848
  at com.codename1.impl.a.b((null):~-1)
  - waiting to lock <0x40526120> (a java.lang.Object) held by threadid=22 (EDT)
  at com.codename1.d.l.a((null):-1)
  at com.codename1.d.o.c((null):-1)
  at com.codename1.d.e.c((null):-1)
  at com.codename1.d.e.c((null):-1)
  at com.codename1.d.e.aq((null):-1)
  at com.codename1.d.s.e((null):-1)
  at com.codename1.d.o.e((null):-1)
  at in.n10k.UltimateGRE.bm.run((null):-1)
  at java.util.Timer$TimerImpl.run(Timer.java:284)

"invokeAndBlock1" prio=6 tid=23 WAIT
  | group="main" sCount=1 dsCount=0 obj=0x4056dc48 self=0x2e44d8
  | sysTid=19883 nice=-2 sched=0/0 cgrp=[fopen-error:2] handle=2917080
  at java.lang.Object.wait(Native Method)
  - waiting on <0x40524b28> (a java.lang.Object)
  at java.lang.Object.wait(Object.java:358)
  at com.codename1.d.ac.run((null):-1)
  at com.codename1.impl.d.run((null):-1)

"Binder Thread #16" prio=5 tid=21 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051b1b8 self=0x2b30a8
  | sysTid=19880 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2830440
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #15" prio=5 tid=20 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051b0f0 self=0x2b2350
  | sysTid=19879 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2827024
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #14" prio=5 tid=19 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051b028 self=0x2b15f8
  | sysTid=19878 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2823608
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #13" prio=5 tid=18 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051af60 self=0x2b08a0
  | sysTid=19877 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2820192
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #12" prio=5 tid=17 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051ae98 self=0x2afb48
  | sysTid=19876 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2816776
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #11" prio=5 tid=16 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051add0 self=0x2aedf0
  | sysTid=19875 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2813360
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #10" prio=5 tid=15 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051ad08 self=0x2ae098
  | sysTid=19874 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2809944
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #9" prio=5 tid=14 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051abd8 self=0x2ad340
  | sysTid=19873 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2806528
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #8" prio=5 tid=13 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051ab10 self=0x2ac618
  | sysTid=19872 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2803160
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #7" prio=5 tid=12 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051aa48 self=0x2ab920
  | sysTid=19871 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2799840
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #6" prio=5 tid=11 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051a980 self=0x2aac28
  | sysTid=19870 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2796520
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #5" prio=5 tid=10 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051a8b8 self=0x2a9f68
  | sysTid=19869 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1188368
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #4" prio=5 tid=9 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051a7b0 self=0x2a92e8
  | sysTid=19868 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1232064
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #3" prio=5 tid=8 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051a6e8 self=0x12c918
  | sysTid=19867 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1231064
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #2" prio=5 tid=7 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x4051a620 self=0x2584a0
  | sysTid=19866 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1190184
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #1" prio=5 tid=6 NATIVE
  | group="main" sCount=1 dsCount=0 obj=0x40517430 self=0x186340
  | sysTid=19865 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1593216
  at dalvik.system.NativeStart.run(Native Method)

"Compiler" daemon prio=5 tid=5 VMWAIT
  | group="system" sCount=1 dsCount=0 obj=0x405165d8 self=0x184dc0
  | sysTid=19864 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1592704
  at dalvik.system.NativeStart.run(Native Method)

"Signal Catcher" daemon prio=5 tid=4 RUNNABLE
  | group="system" sCount=0 dsCount=0 obj=0x40516518 self=0x121f68
  | sysTid=19863 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1592504
  at dalvik.system.NativeStart.run(Native Method)

"GC" daemon prio=5 tid=3 VMWAIT
  | group="system" sCount=1 dsCount=0 obj=0x40516470 self=0x121e30
  | sysTid=19862 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1592304
  at dalvik.system.NativeStart.run(Native Method)

"HeapWorker" daemon prio=5 tid=2 VMWAIT
  | group="system" sCount=1 dsCount=0 obj=0x405163b8 self=0x185cc0
  | sysTid=19861 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=1592240
  at dalvik.system.NativeStart.run(Native Method)
2)Crashes
Exception class
java.lang.IllegalStateException

Source method

m.a()






Stack traces
v1.06
Sep 1, 2012 12:35:23 AM
2 reports/week
2 reports

java.lang.IllegalStateException: Initialize must be invoked before setCurrent!
at com.codename1.f.m.a(Unknown Source)
at com.codename1.f.p.z(Unknown Source)
at com.codename1.f.p.bo(Unknown Source)
at in.n10k.UltimateGRE.c.run(Unknown Source)
at java.util.Timer$TimerImpl.run(Timer.java:284)

So i'll try using another phone and see if this error occurs on that phone or not. 
And thanks, I'll update my plugin and see how the form can be saved. 
-Nikhil.




Chen Fishbein

unread,
Sep 2, 2012, 8:23:02 AM9/2/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com
Regarding use case 2 - found it, each launched raised a new task, changed this to be a single task by default - the build server will be updated with this fix in a few days.

Nikhil

unread,
Sep 2, 2012, 11:29:26 AM9/2/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com
Ok, the error I described above is happening with other phones too. I htink its related to multiple tasks being run. Cool, I'll download the fix when you release it. Thanks.

ayz...@gmail.com

unread,
Sep 3, 2012, 12:00:53 PM9/3/12
to codenameone...@googlegroups.com
Hi,

I experienced this same problem with my app. Everytime I resume after a pause, mmy screen goes blank.

When it loading, I show a loading dialog infiniteprogress box, but when I switch to another app then resume back, the dialog just keep rolling without stopping and the background bcomes blank though it was showing my previous form before I swiched to another app.

Also, let cn1 handle the paused state by default while any user can modify if they desire to.

Regards.

Nikhil

unread,
Sep 4, 2012, 8:43:07 AM9/4/12
to codenameone...@googlegroups.com, ayz...@gmail.com
Hi CHen,

When will the build server be updated  in order to launch a single task every time the app is launched? I need to put my app on the Google play store. Can I do something from my end to handle this ? Maybe edit something in build.xml?

Thanks,
Nikhil

Chen Fishbein

unread,
Sep 4, 2012, 9:23:26 AM9/4/12
to codenameone...@googlegroups.com, ayz...@gmail.com, nikhil...@hotmail.com
you can't patch this, it requires a server update( we will update in a couple of days)

ayz...@gmail.com

unread,
Sep 7, 2012, 7:17:37 AM9/7/12
to codenameone...@googlegroups.com, ayz...@gmail.com, nikhil...@hotmail.com
Hi,

Has the the server been updated?

Shai Almog

unread,
Sep 7, 2012, 12:14:10 PM9/7/12
to codenameone...@googlegroups.com, ayz...@gmail.com, nikhil...@hotmail.com
Yes.

fabrici...@gmail.com

unread,
Sep 10, 2012, 8:14:18 PM9/10/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com
Hi Chen, is there any possibility that this change might have affected the camera snapshot ? I remember that it was working in my project but now it seems like it is restarting the application

Chen Fishbein

unread,
Sep 11, 2012, 6:55:26 AM9/11/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com, fabrici...@gmail.com
Thanks, I will check it.

fabrici...@gmail.com

unread,
Sep 11, 2012, 11:57:59 AM9/11/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com, fabrici...@gmail.com
Just to be sure I double checked the version history of my project and the code that used to work to take the snapshot is untouched.

Is the Android Implementation available somewhere so I can take a look ?

Shai Almog

unread,
Sep 11, 2012, 1:50:52 PM9/11/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com, fabrici...@gmail.com
Its possible the server side code was outdated. I updated the server this a few hours ago.
All the code for everything is in our SVN in our google code project http://code.google.com/p/codenameone/

Chen Fishbein

unread,
Sep 11, 2012, 3:07:56 PM9/11/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com, fabrici...@gmail.com
Ok, it should work now.
Our build server wasn't up to date with the latest android life-cycle changes 

fabrici...@gmail.com

unread,
Sep 11, 2012, 7:25:07 PM9/11/12
to codenameone...@googlegroups.com, nikhil...@hotmail.com, fabrici...@gmail.com
Thanks, now it works  =)

Cheers
Message has been deleted

Gordons

unread,
Jun 6, 2013, 6:37:43 AM6/6/13
to codenameone...@googlegroups.com
I still experience this problem, if I am performing any task that has the infinite progress and I switch to any other application and come back to my application, it hangs, the infinite progress continues endlessly until I force the application to stop.

How can I correct this?

Chen Fishbein

unread,
Jun 6, 2013, 9:27:43 AM6/6/13
to codenameone...@googlegroups.com
dispose the dialog on stop() callback

Agada Godwin

unread,
Jun 6, 2013, 10:22:57 AM6/6/13
to codenameone...@googlegroups.com
I have no idea on how and where to place the code to dispose the dialog.

please help out.


On Thu, Jun 6, 2013 at 2:27 PM, Chen Fishbein <cf2...@gmail.com> wrote:
dispose the dialog on stop() callback

--
--
You received this message because you are subscribed to the Google
Groups "CodenameOne Discussions" group.
 
For more information about Codename One please visit http://www.codenameone.com/
 
To post to this group, send email to
codenameone...@googlegroups.com
To unsubscribe from this group, send email to
codenameone-discu...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/codenameone-discussions?hl=en?hl=en
 
---
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/rKedbRp5nGk/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Shai Almog

unread,
Jun 6, 2013, 2:38:10 PM6/6/13
to codenameone...@googlegroups.com
In your main classes stop() method:
if(Display.getInstance().getCurrent() instanceof Dialog) {
   
((Dialog)Display.getInstance().getCurrent()).dispose();
}



Gordons

unread,
Jul 3, 2013, 6:23:47 AM7/3/13
to codenameone...@googlegroups.com
I am presently testing my Application On BlackBerry Bold 2 and Curve 2 and they still hang if the Application goes on background with an instance of dialog, even when I have used the code below. Because there is no force stop on blackberry, I turn off the phone to stop the application.

what else do I need to do to be able to resume Application after putting it on the background or better still, dispose the dialog?

Shai Almog

unread,
Jul 3, 2013, 11:04:58 AM7/3/13
to codenameone...@googlegroups.com
Try this:
Form f = Display.getInstance().getCurrent();
if(f instanceof Dialog) {
   f
.setTransitionOut(CommonTransitions.createEmpty());
   f
.dispose();
}
current
= Display.getInstance().getCurrent();
if(current instanceof Dialog) {
    // damn nested dialog, just give up
    current = null;
}



Agada Godwin

unread,
Jul 3, 2013, 12:27:57 PM7/3/13
to codenameone...@googlegroups.com

f.dispose();  can't be found, do you mean ((Dialog) f).dispose(); ?

Sent from my Xperia™ smartphone

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.

To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.

Shai Almog

unread,
Jul 4, 2013, 1:19:38 AM7/4/13
to codenameone...@googlegroups.com
Yep. E-Mail programming is difficult, no compiler to check me.

devanand duseja

unread,
Jan 15, 2020, 7:28:31 AM1/15/20
to CodenameOne Discussions
how to open an app automatically after restarting mobile device

Shai Almog

unread,
Jan 15, 2020, 9:34:31 PM1/15/20
to CodenameOne Discussions
Only on Android
Reply all
Reply to author
Forward
0 new messages