Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Android: Camera Causes Application To Restart
Started by EleXX Apr 05 2013 06:05 AM

16 replies to this topic
android camera restart reboot
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

EleXX

[GLOBAL: userInfoPane.html]
EleXX
  • Enthusiast

  • 44 posts
  • Corona SDK

Hello!

 

 

I got problems using the camera with Corona.

 

After taking a picture, sometimes the app is being restarted (including the Corona Trial popup) instead of showing the most recent screen.

 

I have already read the thread here. I have NOT activated a developer option "dont keep activity (destroy all activity....)".

In fact my phone does not provide this option at all (and I guess it is not activated by default).

 

I had the behaviour with my own app, so I tried the Camera Sample App, and I could reproduce it there as well.

 

The problem occured most often under the following circumstances:

  • I installed the app from an apk-File and immediately pressed "Open" after installation to start the app.
  • I took the picture and immediately pressed "Finish" when the picture was ready.

 

My Phone is a HTC Desire S.

 

I searched the ADB Logcat for hints on the problem. This is not easy due to tons of messages.

 

But I have seen a message from the ActivityManager, probably related to this issue, saying

"Checking to restart com.ansca.corona.CoronaActivity: changed=0x0, handles=0x4a0"

 

I can search the log but don't know exactly what to look for. There did not seem to be any more obvious error messages.

 

 

Thanks for your help with this nasty problem!



[TOPIC: post.html]
#2

EleXX

[GLOBAL: userInfoPane.html]
EleXX
  • Enthusiast

  • 44 posts
  • Corona SDK

One more thing:

I always shot the photos at highest Quality (5M).



[TOPIC: post.html]
#3

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

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.

settings =
{
   android =
   {
      largeHeap = true,
   }
}



[TOPIC: post.html]
#4

EleXX

[GLOBAL: userInfoPane.html]
EleXX
  • Enthusiast

  • 44 posts
  • Corona SDK

Thanx for your help!

 

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!



[TOPIC: post.html]
#5

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

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?



[TOPIC: post.html]
#6

EleXX

[GLOBAL: userInfoPane.html]
EleXX
  • Enthusiast

  • 44 posts
  • Corona SDK

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?



[TOPIC: post.html]
#7

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

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.

 

Anyways, I hope this helps.



[TOPIC: post.html]
#8

cbriggsnz

[GLOBAL: userInfoPane.html]
cbriggsnz
  • Contributor

  • 283 posts
  • Corona SDK

I have a similar issue on my Samsung S2, and my clients S3.  I have added the code "largeHeap = true" and I will let you know if this helps..



[TOPIC: post.html]
#9

EleXX

[GLOBAL: userInfoPane.html]
EleXX
  • Enthusiast

  • 44 posts
  • Corona SDK

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".



[TOPIC: post.html]
#10

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

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...

http://stackoverflow.com/questions/7473061/startactivityforresult-but-not-on-my-apps-activity-stack

http://stackoverflow.com/questions/10910227/startactivityforresult-in-low-memory-situations?rq=1

 

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.

http://docs.coronalabs.com/api/library/audio/dispose.html

 

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...



[TOPIC: post.html]
#11

EleXX

[GLOBAL: userInfoPane.html]
EleXX
  • Enthusiast

  • 44 posts
  • Corona SDK

Hi!

 

 

Understanding the problem is the first step in solving it... :)

 

I have no audio in my app yet. There may come some sound effects, but probably not many of them.

What I have in memory are images, because I crop the pictures shot with the camera (downscaled) and show them in a scrollView.

 

I will do further testing with the Corona-camera app, but it seems ok at first glance.

 

Thanx for your help!



[TOPIC: post.html]
#12

zdeveloper

[GLOBAL: userInfoPane.html]
zdeveloper
  • Contributor

  • 125 posts
  • Corona SDK

[TOPIC: post.html]
#13

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Our updated guides can be found here...

http://docs.coronalabs.com/guide/index.html



[TOPIC: post.html]
#14

zdeveloper

[GLOBAL: userInfoPane.html]
zdeveloper
  • Contributor

  • 125 posts
  • Corona SDK

We have been using Corona now for about two years for our app development.  This issue where the app restarts when taking a picture persists on Android.

 

After lots of testing and debugging, I do not thing this is a memory issue.  I can get the restarts to occur with a fresh install of Lollipop on a Galaxy S5 using just the simple Corona camera test app. We've seen this same error on Galaxy S4, Notes, as well

 

We have thousands of users using our app...I know of 2 customer reports of this issue.  Both on Samsung devices too.  

 

I know this sounds crazy, but, after taking thousands of test pictures in different conditions, I think there is a good chance this is actually a battery/low voltage issue.  If the resolution is reduced to 12 MP or below, the error almost never happens.   I believe Samsung changes some system operation items below 20% battery capacity to save power....the issue goes away.  

 

Interestingly, we cannot get the issue to occur when we are in debug mode so we can actually see what is going on...guess what, USB cable is connected and we are charging. 

 

This is not a 100% diagnosis.  But, we are 5 engineers have done thousands of tests to try and re-produce this.  This is the most correlated thing we can find.  We have stuck in memory logs everywhere...the device has plenty of memory, the reported app memory is 12MB.  

 

We desperately need Corona to take another look at this issue and resolve.  Even if you could give us control of camera resolution, the problem would go away as well.  



[TOPIC: post.html]
#15

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,263 posts
  • Enterprise

We will need a bug report to get Engineering to look at this.

 

Rob



[TOPIC: post.html]
#16

cublah

[GLOBAL: userInfoPane.html]
cublah
  • Contributor

  • 379 posts
  • Corona SDK

I'm also experiencing this on a Galaxy S5, not every picture but enough to be annoying to the user.



[TOPIC: post.html]
#17

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,263 posts
  • Enterprise

We still need a bug report. Please post the Case # you get in the email back here.

 

Thanks

Rob




[topic_controls]
[/topic_controls]