prevent activity restart on resume?

5,737 views
Skip to first unread message

Mehuge

unread,
Nov 2, 2012, 9:36:05 AM11/2/12
to phon...@googlegroups.com
Hi.  

Using cordova android, when I hit the home button on the device, then later resume that app (while its still running in memory) the activity is restarted, and my content reloaded.  I already make provision for this and am able to resume state within my app, but its ugly to say the least, and time consuming, and dare I say pointless, as the app is already there in background.

To combat this, I *was* using the AndroidManifest.xml activity setting to force a single instance

<activity android:launchMode="singleInstance" ...

and that worked great. If the process was still running in memory, the activity would simple be brought into foreground, no reloading of the web content occuring.

However, I later found that using this option, prevents cordova.camera.getPicture() from working, the camera always returns a cancelled state even when save is selected, and this wasn't due to lack of memory (no exceptions or stack traces). The only clue being the following line in logcat just after selecting Save in the camera (and therefore resuming my app)

W/ActivityManager( 1854): Activity is launching as a new task, so cancelling activity result.

So I was forced to take this singleInstance option out to get the camera code working again.

That is the background of the problem and where I am at. My question is:-

Is there a setting for android:launchMode (or other setting) that will bring an existing instance of the activity into foreground and not restart it?  
Or is there a different way of launching the webview in the cordova client java code that would prevent this?

elsigh

unread,
Nov 30, 2012, 1:31:50 PM11/30/12
to phon...@googlegroups.com
Dealt with this yesterday myself, try android:launchMode="singleTask"

Airblader

unread,
Nov 30, 2012, 2:32:51 PM11/30/12
to phon...@googlegroups.com
I'm using

<preference name="exit-on-suspend" value="false" />

in the config.xml

Austin France

unread,
Nov 30, 2012, 5:50:55 PM11/30/12
to phon...@googlegroups.com
I did end up using launchMode="singleTask" in the end.

Thanks

Regards
Austin





--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 

Chris

unread,
Sep 24, 2013, 2:40:22 PM9/24/13
to phon...@googlegroups.com
$ cordova build (the CLI) keeps overwriting this setting on me - anyone know how to fix/avoid that?

Didier Baquier

unread,
Dec 19, 2013, 6:27:08 PM12/19/13
to phon...@googlegroups.com
exit-on-suspend do not the job I also ended up with android:launchMode="singleTask" 
Reply all
Reply to author
Forward
0 new messages