Cordova: App restarting after using the camera
The question you mention may be 4 years old, but the issue remains the same: Android is killing off your Cordova app activity while it has been put in the background and the camera activity is in the foreground (see the Cordova documenation for a detailed explanation of the issue).
The essence of the accepted answer to that question is also still correct, but the plugins mentioned are out-of-date / have not been updated for new versions of Cordova.
I would suggest using one of the more recently updated forks (e.g https://github.com/zebra1024/cordova-plugin-wezka-nativecamera) of cordova-plugin-wezka-nativecamera
as the foreground camera plugin, since the original repo hasn't been updated in 2 years and has issues with the latest versions of Cordova.
PhoneGap camera restarts the application
This problem isn't actually about Phonegap. It's a common issue on native android apps too.
It occurs because when the camera is triggered, the android activity goes background (onStop state), waiting for the camera to take the picture. Then the GC comes and kills the activity to free memory before the conclusion of camera action, and when the camera is done your activity has already died. That is why the app is restarted.
It's on Android Lifecycle docs (http://developer.android.com/reference/android/app/Activity.html ):
If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.
The same occurs by acessing the media gallery or other resources that causes your activity to go background. Phonegap (now Cordova) team is already working to improve this ( https://issues.apache.org/jira/browse/CB-14 ).
We had this problem in our company and the solution was to natively develop a Phonegap plugin to use our customized camera, then our activity never go to onStop state. Follow the android API instructions on http://developer.android.com/guide/topics/media/camera.html#custom-camera and try it too.
See ya!
Edit 1:
We submited a Google Code project named Foreground Camera Plugin that fixes the problem of Android Camera restarting Phonegap applications. There is some orientation on how to use it too. Please see: http://code.google.com/p/foreground-camera-plugin/
Edit 2:
Since this problem happens with gallery too, we submited another Google Code project named Foreground Gallery Plugin that works with Cordova and fixes this issue. Please see: http://code.google.com/p/foreground-gallery-plugin/
Camera in phonegap app. restarting the app
The phonegap camera API invokes the camera application when you use
navigator.camera.getPicture
Please read it here - http://docs.phonegap.com/en/edge/cordova_camera_camera.md.html#Camera
This pushes your application into the background and that can lead to your app being killed if there isn't enough memory.
If you don't want your application to go into background while the camera is up, you need to use a foreground camera plugin. Take a look at it here
You might need to change it to suit your requirements.
Cordova app restart after getting picture from capture or photo Librairie
By luck, i've tried to change the html code, just in case, and here is the solution:
I just change this code:
<button onclick="capturePhoto();">Capture Photo</button>
to this:
<a href="" class="ui-btn" onclick="capturePhoto();">Capture Photo</a>
Don't use html buttons tag, use anchor tag... don't know why but this worked !!!
Phonegap Android application restarting instead of resuming, although it was not killed by the OS
You want to add the following to the activity tag in your AndroidManifest.xml:
android:launchMode="singleTask"
So it should look like this:
<activity android:name="MyApp" android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:launchMode="singleTask">
Check out this page for more information on launchMode: http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode
Related Topics
How to Make Notification Intent Resume Rather Than Making a New Intent
Firebase Overwrites Signin with Google Account
Convert Arraylist<Mycustomclass> to JSONarray
How to Simulate Touch from Background Service with Sendevent or Other Way
How to Downgrade Android Emulator
Parse JSON Array Without Key in Android
Send Data Back to the Script Which Started the Activity via Adb Shell Am Start
How to Re-Sign an .Apk with a Different Certificate Than What It Came With
What Is the Class R in Android
First Launch Take Long Time (Classloader Referenced Unknown Path)
How to Send Multiple Sms to Single Number
Android: Share Plain Text Using Intent (To All Messaging Apps)
Android: Determine Security Type of Wifi Networks in Range (Without Connecting to Them)
Get the Background Color of a Button in Android
Getlastknownlocation Always Return Null After I Re-Install the APK File via Eclipse