Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After Clicking Photo, App RESTARTS, #918

Open
pjdpaulsagnik opened this issue Nov 24, 2024 · 1 comment
Open

After Clicking Photo, App RESTARTS, #918

pjdpaulsagnik opened this issue Nov 24, 2024 · 1 comment

Comments

@pjdpaulsagnik
Copy link

Bug Report
Problem Description
Expected Behavior
To be able to take photos using the camera.

Actual Behavior
After Clicking Photo, App RESTARTS,

Related Information
Reproduction Steps:
Launch the app.
Activate the camera function and tap the capture button.
After Clicking Photo, App RESTARTS,
Additional Context or Information:
Device: Redmi Note 9 Pro, Vivo Max

Operating System: Android 12, 13
cordova plugin list
backgroundapprun 0.0.1 "backgroundAppRun"
cordova-background-geolocation 4.15.0 "BackgroundGeolocation"
cordova-plugin-android-permissions 1.1.5 "Permissions"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-background-fetch 7.2.4 "CDVBackgroundFetch"
cordova-plugin-background-mode 0.7.3 "BackgroundMode"
cordova-plugin-camera 8.0.0 "Camera"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-dialogs 2.0.1 "Notification"
cordova-plugin-file-opener2 3.0.5 "File Opener2"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-firebasex 14.0.0 "Google Firebase Plugin"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 5.0.0 "cordova-plugin-ionic-webview"
cordova-plugin-network-information 3.0.0 "Network Information"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-streaming-media 2.3.0 "StreamingMedia"
cordova-plugin-vibration 3.1.0 "Vibration"
cordova-plugin-whitelist 1.3.5 "Whitelist"
cordova-plugin-x-socialsharing 6.0.4 "SocialSharing"
cordova-plugin-x-toast 2.7.3 "Toast"
es6-promise-plugin 4.2.2 "Promise"

Command or Code
$scope.showActionSheet = function () {
console.log("LOG Action Sheet !");
$ionicPopup.show({
title: 'Upload Image',
subTitle: '',
scope: $scope,
buttons: [
{ text: '

Camera

' ,
onTap: function(e) {
$scope.openCameraTEST();
}
},
]
});
};

    $scope.openCameraTEST = function () {

        var options = {
            quality: 75,
            allowEdit: false,
            sourceType: 1,
            destinationType: 0
        };
       if( this.device.version <= 11 ){
              cordova.plugins.backgroundMode.enable();
        }
        Camera.getPicture(options).then(function (imageData) {
            console.log("imageData : ",imageData);

            if( this.device.version <= 11 ){
                 cordova.plugins.backgroundMode.disable();
            }
            $scope.data.doc_path = "data:image/jpeg;base64," + imageData;
            console.log("$scope.data.doc_path : ",$scope.data.doc_path);
        }, function (err) {
            console.log(err);
        });
    }

Environment, Platform, Device
Platform: Android
Device: Redmi Note 9 Pro, Vivo Max

Version Information
Cordova: Cordova Android 13.0.0
Operating System: Android 12, 13

Checklist
Searched for existing GitHub issues.
Included all the necessary information above.

Problem :

WHILE USING BACKGROUND MODE IN TARGET - SDK 34,

SOME PHONES WITH ANDROID 12, 13, WORKS FINE WITHOUT USING BACKGROUND MODE,

BUT SOME some phones App reloads, no error in LOGCAT of Android Studio,
App just restarts. Error happening in very few devices

@breautek
Copy link
Contributor

What you're describing sounds like an expected flow when using Intents, which is the Android mechanism of delegating a task to another application (e.g. the Camera).

Why is this a thing?

When the camera intent is launched, and the camera application is launched, it puts your app activity (The "thing" that holds your application's UI) in the background. The OS may kill the activity if it believes it's necessary for smooth operation of the foreground application. The exact details of how Android decides this is not known to us, and can probably vary by device hardware configuration and installed applications.

What can be done?

But nonetheless the OS killing the activity is an expected workflow that should be handled. It's quirk is documented here with a link containing more details about the android lifecycle.

How can I test this?

You can force android to always use this flow for testing purposes by enabling the Don't Keep Activities developer option on the device, which will make Android always kill background activities.

Other notes

A note on this background mode thing you've mentioned, which I assume is provided by cordova-plugin-background-mode plugin. It appears to setup a ForegroundService. A Service is something that an Activity can start, and can run in the background, independently from the activity. It's useful in native development to perform background task that might be long-running. a ForegroundService is a specific kind of service that allows UI to be displayed in the notification center. So that the service can provide progress feedback to the user. It's not that useful in Cordova applications because most of your state is inside the web application, which cannot be decoupled from the webview, and thus cannot be decoupled away from the activity.

Services cannot keep an activity alive in the background, but a service can continue running after the activity is destroyed. It has no relevance to how the application behaves when using Intents.

If you can confirm if this is what you are experiencing, please let me know.
Otherwise if you still think there is a bug, we'll likely need a sample reproduction app that can demonstrate the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants