Your device might be running out of memory when taking high res camera shots, forcing Android to force quit apps running in the background. Have a look at the Android log via “adb logcat” or “ddms” to see if this is happening.
You can also try requesting the Android OS to give your app a larger heap (ie: more memory) by adding the following setting to your “build.settings” file. Note that typically only Android 4.0 or higher devices respect this setting.
I tried the “largeHeap” setting, but it did not change the behaviour. This is probably due to the fact my device is only running Android 2.3.5.
I searched the logcat output intensely. I could not find any hints that were obviously related to the issue besides the line I already noted in my first post.
But I must admit that it is very difficult to analyze and understand the whole logcat output without deep knowledge of the Android OS.
Because I could reproduce the problem with the camera sample app, I think there must be other people that encountered this issue too. If it only happens on very specific and rare device / OS configurations, I can live with it.
But if it happens on many devices (especially if they are only a few years old and use the highest camera resolution, which is a common usecase in my opinion), this is quite a dealbreaker for apps using the camera!
I have older devices than yours, such as a 1st generation Droid and an HTC Evo 4G which are both running Android 2.2, and they don’t have this issue. The camera sample app works fine on them.
Does rebooting your phone help any? (I’m hoping it will close all other apps and free up memory.)
Or perhaps your device is out of storage space?
One more thing. You said you sometimes see a Corona “Trial” popup when displaying your app. The newest release version of Corona, build #1076", should no longer displays a trial popup. So, have you tried upgrading to the newest release version?
Storage space is probably not the problem. My internal space is above 400 MB, external over 5 Gigs.
I furthermore downloaded the most recent version of the Corona SDK.
This did not fix the problem, but introduced a new issue with the ScrollView. The “takeFocus(event)” function of the ScrollView seems to be “nil” now. The same code was working before. Have there been any changes?
But rebooting the device really did help! Afterwards I could not provoke the error anymore.
But I guess the end-user will not be happy with this “workaround”. Are there other possibilities, or shall we cancel this issue as too rare to be dealt with?
If rebooting solved the problem, then it sounds like you had too many apps running in the background eating up system memory. What likely happened was that displaying the camera activity window forced other apps that were running in the background to be shutdown, and unfortunately, your app was one of them. I don’t think we can do anything about that. Android does not give us permission to force quit other apps running in the background because that would be a security issue. Also, Corona frees up as much memory as possible by unloading all textures/images before suspending itself to prevent Android from force quitting the app. That’s as much as we can do. I will say that this is the first time I’ve heard of this happening, so I hope that makes this a very rare case.
The only other thing I can offer is instead of displaying the device’s default camera app for taking pictures, you can use Corona’s built-in camera activity instead. You can do this by *removing* the “WRITE_EXTERNAL_STORAGE” permission, but you still have to set the “CAMERA” permission. Corona’s camera activity is very basic though because it was meant to be used as a fallback mechanism in case a camera app could not be found on the device.
It is very important for me to understand the cause for this problem. Your explanation seems quite feasible.
I have tried Corona’s built-in camera app, and first tests went very well. There were no more unexpected restarts. The user can take pictures very easily. Does it work on iOS the same?
Disadvantages are that users cannote “retake” a picture (not a big deal for my app), and the camera preview seemed a bit distorted (but the final pictures were not).
Even an advantage for my app is the fact that pictures taken with the Corona camera-app are not included in Android’s gallery (which was kind of annoying with the native camera-app).
Thanx for this info, I did not know that there even was a built-in camera app. I think a description to this fact would be an important addition for the API-documentation of “media.show”.
Come to think of it, I think setting largeHeap to true might make it worse, because if the device is running low on memory, then the OS is more likely to quit apps that use the most memory on the device first. Although I’m shocked that the operating system would decide to take out apps that belong to the same “task” as the app that launched it.
I did a quick Internet search about this issue and discovered that this is unfortunately a common issue on Android…
Do you happen to have a lot of other things loaded in memory such as audio? If so, then perhaps you should dispose of your audio data when your app is being suspended so that Android is less likely to take out your app during these memory starved situations.
You may also want to call Lua’s collectgarbage() function to ensure all unreferenced Lua objects get collected as well.
Other than that, I’m not sure what else can be done since this is an out-of-memory issue. The reason displaying Corona’s internal Corona camera activity works around this problem is because it belongs to your app. So, that’s the only guaranteed way around this, but unfortunately I don’t think we can detect these out-of-memory situations until it’s too late. Hmm…
Your device might be running out of memory when taking high res camera shots, forcing Android to force quit apps running in the background. Have a look at the Android log via “adb logcat” or “ddms” to see if this is happening.
You can also try requesting the Android OS to give your app a larger heap (ie: more memory) by adding the following setting to your “build.settings” file. Note that typically only Android 4.0 or higher devices respect this setting.
I tried the “largeHeap” setting, but it did not change the behaviour. This is probably due to the fact my device is only running Android 2.3.5.
I searched the logcat output intensely. I could not find any hints that were obviously related to the issue besides the line I already noted in my first post.
But I must admit that it is very difficult to analyze and understand the whole logcat output without deep knowledge of the Android OS.
Because I could reproduce the problem with the camera sample app, I think there must be other people that encountered this issue too. If it only happens on very specific and rare device / OS configurations, I can live with it.
But if it happens on many devices (especially if they are only a few years old and use the highest camera resolution, which is a common usecase in my opinion), this is quite a dealbreaker for apps using the camera!
I have older devices than yours, such as a 1st generation Droid and an HTC Evo 4G which are both running Android 2.2, and they don’t have this issue. The camera sample app works fine on them.
Does rebooting your phone help any? (I’m hoping it will close all other apps and free up memory.)
Or perhaps your device is out of storage space?
One more thing. You said you sometimes see a Corona “Trial” popup when displaying your app. The newest release version of Corona, build #1076", should no longer displays a trial popup. So, have you tried upgrading to the newest release version?
Storage space is probably not the problem. My internal space is above 400 MB, external over 5 Gigs.
I furthermore downloaded the most recent version of the Corona SDK.
This did not fix the problem, but introduced a new issue with the ScrollView. The “takeFocus(event)” function of the ScrollView seems to be “nil” now. The same code was working before. Have there been any changes?
But rebooting the device really did help! Afterwards I could not provoke the error anymore.
But I guess the end-user will not be happy with this “workaround”. Are there other possibilities, or shall we cancel this issue as too rare to be dealt with?
If rebooting solved the problem, then it sounds like you had too many apps running in the background eating up system memory. What likely happened was that displaying the camera activity window forced other apps that were running in the background to be shutdown, and unfortunately, your app was one of them. I don’t think we can do anything about that. Android does not give us permission to force quit other apps running in the background because that would be a security issue. Also, Corona frees up as much memory as possible by unloading all textures/images before suspending itself to prevent Android from force quitting the app. That’s as much as we can do. I will say that this is the first time I’ve heard of this happening, so I hope that makes this a very rare case.
The only other thing I can offer is instead of displaying the device’s default camera app for taking pictures, you can use Corona’s built-in camera activity instead. You can do this by *removing* the “WRITE_EXTERNAL_STORAGE” permission, but you still have to set the “CAMERA” permission. Corona’s camera activity is very basic though because it was meant to be used as a fallback mechanism in case a camera app could not be found on the device.
It is very important for me to understand the cause for this problem. Your explanation seems quite feasible.
I have tried Corona’s built-in camera app, and first tests went very well. There were no more unexpected restarts. The user can take pictures very easily. Does it work on iOS the same?
Disadvantages are that users cannote “retake” a picture (not a big deal for my app), and the camera preview seemed a bit distorted (but the final pictures were not).
Even an advantage for my app is the fact that pictures taken with the Corona camera-app are not included in Android’s gallery (which was kind of annoying with the native camera-app).
Thanx for this info, I did not know that there even was a built-in camera app. I think a description to this fact would be an important addition for the API-documentation of “media.show”.
Come to think of it, I think setting largeHeap to true might make it worse, because if the device is running low on memory, then the OS is more likely to quit apps that use the most memory on the device first. Although I’m shocked that the operating system would decide to take out apps that belong to the same “task” as the app that launched it.
I did a quick Internet search about this issue and discovered that this is unfortunately a common issue on Android…
Do you happen to have a lot of other things loaded in memory such as audio? If so, then perhaps you should dispose of your audio data when your app is being suspended so that Android is less likely to take out your app during these memory starved situations.
You may also want to call Lua’s collectgarbage() function to ensure all unreferenced Lua objects get collected as well.
Other than that, I’m not sure what else can be done since this is an out-of-memory issue. The reason displaying Corona’s internal Corona camera activity works around this problem is because it belongs to your app. So, that’s the only guaranteed way around this, but unfortunately I don’t think we can detect these out-of-memory situations until it’s too late. Hmm…