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

appStateChange fired too late #479

Closed
no-creative-name opened this issue Jun 16, 2021 · 5 comments
Closed

appStateChange fired too late #479

no-creative-name opened this issue Jun 16, 2021 · 5 comments

Comments

@no-creative-name
Copy link

Bug Report

Plugin(s)

@capacitor/app

Capacitor Version

@capacitor/cli: 3.0.1
@capacitor/android: 3.0.1
@capacitor/core: 3.0.1
@capacitor/ios: 3.0.1

Platform(s)

Android

Current Behavior

Since for our app security/data privacy is a huge factor, we need to implement a way that the app content is hidden (white screen) when the app is backgrounded (e.g. in the task manager). For this is wanted to use the "appStateChange" event listener from @capacitor/app. The problem is that the event only fires when coming back into the app after putting it into the background. This makes it unusable for our use case.

Expected Behavior

"appStateChange" also fires before/when the app is backgrounded.

Other Technical Details

Tested on a real Android device and a simulated one.

@no-creative-name
Copy link
Author

I found https://github.com/capacitor-community/privacy-screen to be able to hide the screen in the task manager. Still I think this should work as expected.

@Ionitron
Copy link
Collaborator

Ionitron commented Jul 6, 2022

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks!
Ionitron 💙

@shpasser
Copy link

This issue does not need any more information.

In order to reproduce the issue just build an Android app using the plugin and use the supplied example:

import { App } from '@capacitor/app';

App.addListener('appStateChange', ({ isActive }) => {
  console.log('App state changed. Is active?', isActive);
});

While debugging the app enable the debug console in Android Studio and look for App state changed. Is active? and you will see that only the resume events are handled.

In order to reproduce the pause/resume behavior just leave and re-enter the app on your phone.

The behavior in Android is buggy while in iOS it works as expected.

@shpasser
Copy link

shpasser commented Jul 11, 2022

I think that the actual issue is here:

https://github.com/ionic-team/capacitor/blob/ee2069a6e9d3d52e232a31d35909faf87c272c7c/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java#L91

The function should call bridge.getApp().fireStatusChange(false) but it doesn't.

@jcesarmobile
Copy link
Member

jcesarmobile commented Sep 2, 2022

Sorry, but I can't reproduce.
the event is being fired on onStop, not on onPause, that's why the code is not on that line, but it's being fired on my app.

There is an feature request open for including more states so it could be fired on pause.
#1153

Also, for Cordova compatibility we also fire the cordova pause event, you can use it like this: document.addEventListener("pause", yourCallbackFunction, false);

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2022
@ionic-team ionic-team locked as resolved and limited conversation to collaborators Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants