8

Fixed: "Do not keep activities" is default on SG3

Samsung Galaxy S3 ships with "Do not keep Activities" on by default (test models in two locations were both having this fault out the box)

Of course this means that as soon as any other activity is started, including from within your Cordova/PhoneGap app, your app's main activity will be destroyed. Any callback events will obviously never fire.

Switching the option off fixes the problem.

Check developer options regardless of brand/model, for example Asus Nexus 7 tablets do not have this default.


I've setup a basic test app. Which has a button and an img tag + the unmodified Cordova index.js

Button onclick is calling capturePhoto():

function onPhotoURISuccess(imageURI) {
  console.log(imageURI);
  var largeImage = document.getElementById('largeImage');
  largeImage.style.display = 'block';
  largeImage.src = imageURI;
}

function capturePhoto() {
  navigator.camera.getPicture( onPhotoURISuccess, onFail, 
     { quality: 20, allowEdit: true, destinationType: Camera.DestinationType.FILE_URI });
}

function onFail(message) {
  alert('Failed because: ' + message);
}

When I run the app on the simulator and also on a Asus Nexus 7 Tablet, the Camera opens as expected, allows a photo to be taken and confirmed, and then returns with the FILE_URI and sets the image src attribute.

However on a Samsung Galaxy SIII, (we are testing with two in different locations) the Camera opens, allows a capture, and after confirmation, attempts to resume the test app and dies.

Does anyone know of this problem, and is there a way to fix it?

FYI, I've added an extra setting to the AndroidManifest.xml activity node : android:screenOrientation="nosensor" - although this doesn't solve the issue (clutching at straws here.)

Other info:

  • Phone is running Android 4.1.2
  • Targetting sdk 16
  • Cordova v 2.4.0rc1

Tested versions of phonegap - 1.8 - 2.4rc (all crash or fail to return image.)

Relevant portion of the stacktrace is here: http://pastie.org/5974920

Update

  • regarding Simon MacDonald's suggestion.

Tested with quality : 100

Same results as before.

  • 1.9-2.1 bomb (no message)
  • 2.2-2.3 get back to the app, but no image.
  • 2.4 - sorry the app has stopped - "managed" crash

None working.

ocodo
  • 29,401
  • 18
  • 105
  • 117
  • I think I've come across this problem, is it reopening the index.html page after you have finished with the live camera? – Clinton Ward Jan 31 '13 at 05:51
  • On 2.2.0 and 2.3.0 it does manage to get back to the app/index.html. on all other versions I've tried, 1.8, 1.9, 2.0, 2.1 & 2.4rc1 it crashes back to the OS. - This is definitely a Samsung only issue, which sucks, as they're really popular. – ocodo Jan 31 '13 at 10:21
  • @ClintonWard - oh I should also mention, that while 2.2.0 and 2.3.0 get back to index.html, the image is not returned. – ocodo Jan 31 '13 at 11:07
  • 1
    I know this sounds counter intuitive but can you specify a quality of 100 and see if you can reproduce the issue? – Simon MacDonald Jan 31 '13 at 14:46
  • i've found a similar issue with the samsung note, i will try image quality 100 – Clinton Ward Jan 31 '13 at 17:19
  • @SimonMacDonald thanks for the info Simon, very counter intuitive, I'll give it a try. – ocodo Jan 31 '13 at 23:08
  • @SimonMacDonald - no joy I'm afraid. (tried with 2.3.0) - will try with latest. – ocodo Jan 31 '13 at 23:21
  • @SimonMacDonald - see my latest edit. Effectively the same results as `quality:20` (tried 50 for fun too, cargo culting! let's do it!) – ocodo Feb 01 '13 at 01:02
  • @Slomojo Whether i facing the same issue.Can i know how you solve this issue – Fazil Nov 08 '13 at 06:07
  • @Fazil see the answer I provided below. – ocodo Nov 08 '13 at 08:58
  • Thanks - this saved me a load of debugging and heartache. In my case the particular option you mentioned on the S2 was not checked but disabling developer options altogether fixed the issue. Thanks. – DavidC Dec 18 '13 at 10:32
  • @DavidC - glad it helped, the issue had caused me problems for a couple of weeks at least. – ocodo Dec 18 '13 at 12:00

3 Answers3

7

On the Samsung Galaxy 3 the developer option Do not keep activities is on by default.

This will garbage collect your main activity when you launch any other, in this case the Camera.

Switching off the option solves the problem.

ocodo
  • 29,401
  • 18
  • 105
  • 117
  • For me switching off main Developer Options switch fixes the issue as that option was not checked (Galaxy S2). – DavidC Dec 18 '13 at 10:33
  • @DavidC - that will switch off the above mentioned option, but obviously will turn off your ability to debug as well, so ... maybe not so useful. - Note, just read your other comment about the lone option not being there... painful. – ocodo Dec 18 '13 at 11:57
  • I'm on the Galaxy s5 and I can't find a way to prevent restarting even if I switch off "Do not keep activities" or turn off Developer Options. – tslater Mar 08 '15 at 01:47
  • Developer mode must be on. I expect you have a slightly different issue – ocodo Mar 08 '15 at 05:45
2

I have a Samsung Galaxy Note II. I had the same problem. I changed this in the AndroidManifest.xml and now it works on Samsung and HTC Thunderbolt

<uses-feature android:name="android.hardware.camera" android:required="false"/>

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="10"/>

<activity  android:configChanges="orientation|keyboardHidden" />
user372225
  • 851
  • 2
  • 9
  • 23
  • Which version of cordova/phonegap, I've tried with 2.5.0 and 2.3.0. I'm still having issues resuming properly. – ocodo Mar 07 '13 at 06:56
1

Do you have background processes turned off? If so, this will break ALL Android cameras. The data being passed back in the intent can't be null.

Also, be certain to add this to your Android Manifest:

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"  

The fact that 2.4.x crashes is a bug, since something broke that handled the resume state in this case, but the fact is that you need background processes to pass the data from one intent to another, otherwise this won't work with any Android application. We at least start to gracefully handle this case. The app closing I think may be a bug, so I'd be interested in seeing a ticket here: https://issues.apache.org/jira/browse/CB

Update: See https://issues.apache.org/jira/browse/CB-2533

Joe B
  • 596
  • 4
  • 11
  • We're not touching background processes, we test this same setup with an Asus/Google Nexus 7 tablet with no issues. - There's a fairly long list of Samsung reports on the related Google Group. The ostensible error is "Out of Memory" however, this is a File URI return (which we're now just showing as text in an alert, to avoid any memory issues loading the image into Webkit) ... I'm using 2.3.0 presently and as you can see from my edits, 2.3.0 resumes, albeit without returning the URI. – ocodo Feb 07 '13 at 22:09
  • I understand that it's File URI, except that nothing is being passed back from the Camera. I've only seen this issue on devices by limiting the background processes, but if the Samsung camera app has memory issues, that may cause this as well. We depend on the app provided by the phone manufacturer to actually work, and unfortunately it doesn't seem to work in your case. I still don't know why I can't reproduce your memory errors though. – Joe B Feb 07 '13 at 22:24
  • I see, it's definitely Samsung specific, however, It's not presenting as "Out of memory" in my stack traces. [Here's a gist of a stacktrace I've just generated](https://gist.github.com/4735009) – ocodo Feb 07 '13 at 22:59
  • FYI - I mentioned the error is ostensibly "Out Of Memory" because that seems to be the general thinking on the related google group (and is shown in several stack traces there.) – ocodo Feb 07 '13 at 23:01
  • Are you trying to take a picture or take video? I see the application pause and then a bunch of comments about writing to an AudioCache. I think the audio writing to the cache is causing you to run out of memory. – Joe B Feb 12 '13 at 04:40
  • just taking a photo, I saw all the audio / awesome player stuff too, but grep that stacktrace, there's no mention of out of memory. – ocodo Feb 12 '13 at 08:40
  • it turned out to be **Do not keep activities** in the developer options. Lots of other red-herrings along the way. – ocodo Mar 20 '13 at 02:57
  • Thought so! If you don't keep Activities they can't run in the background. The Camera App needs to run in the background to save the photo and pass it back. – Joe B Mar 25 '13 at 20:43
  • Thanks for the 20/20 hindsight Joe ;-) - I think the real question is why doesn't Android log "activity killed : developer option" or something less cryptic so you can trace it. Or more importantly why the hell does Samsung ship phones with this as a developer default? – ocodo Mar 25 '13 at 22:23
  • All Android devices ship with this, it's to stress-test applications. Too bad they didn't do this testing with their camera. – Joe B Apr 09 '13 at 21:35
  • I've got a few other android devices here, and the Samsung is the only one with this set as a default – ocodo Apr 10 '13 at 01:10