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

Use new method to determine if app is in foreground #7418

Closed
estampscvt opened this issue Oct 23, 2023 · 7 comments
Closed

Use new method to determine if app is in foreground #7418

estampscvt opened this issue Oct 23, 2023 · 7 comments
Labels
help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. platform: android Type: Stale Issue has become stale - automatically added by Stale bot

Comments

@estampscvt
Copy link

Per android developer guide this function should only be used for debugging and apps in the past have been rejected from the google play store when included.

@mikehardy
Copy link
Collaborator

Interesting. I'm not sure how converting to the a lifecycle-based solution would be possible while still supporting these features / requirements:

1- allow configuration of unrelated activities as background activities: #5235
2- correctly answer "false" (app/activity is in background) even for multi-process apps that may have other components in foreground

There are some side requirements for a good implementation of lifecycle aware components like "don't leak contexts" and for react-native apps like "we cannot extend the Application easily" - meaning it is difficult to get control during the lifecycle in order to attach a listener or detach a listener

As a rough guess at a modern implementation, if you just do a state check like this https://stackoverflow.com/a/52678290/9910298 then you may be able to get the state similar to the current implementation without worrying about attaching/detaching listeners but you won't be able to support background activity ignore as in PR 5235 linked above

It may be that activityManager.getRunningAppProcesses - in it's continuing efforts to close down information leaks that reduce security in current Android APIs is already returning a list of running processes so reduced - that is, only a single entry even if you have an app with multiple processes! - that the worry above about multi-process apps does not apply. There would still be the question of background activities though

All in all - not sure what the implementation that meets all the requirements + existing functionality should be here and it will require a fair bit of testing. I'm open to a PR if you want to take it on

@mikehardy
Copy link
Collaborator

I just finished reading up all the available android developer docs.
The warning you cite has been in place forever yet the implementation does continue to function and I'm not aware of a competing implementation that could take over so I am going to close this as I do not think it is feasible.

However! I could of course be wrong. I still would be happy to accept a PR that swaps the current implementation for one of the modern lifecycle style APIs but it would need to handle the constraints of being implemented in a non-Application extending / non-Activity-owning react-native context, and would need to implement ignore of a list of activities + work across multiple app processes as I think that's current behavior

@estampscvt
Copy link
Author

estampscvt commented Oct 30, 2023

Hey @mikehardy I saw this fix in another library we use and that is also trying to determine if the app is in foreground. Would this type of fix be possible? https://github.com/invertase/notifee/blob/f78a56518b1fe0dab060e96c2a1f145e41b7363a/packages/react-native/android/src/main/java/io/invertase/notifee/NotifeeReactUtils.java#L201

@estampscvt
Copy link
Author

@mikehardy Just wanted to circle back and see what you think of that suggestion/if it would work here

@mikehardy
Copy link
Collaborator

Very interesting - I'm involved in that repo as well but haven't been active there for a while. Generally the stuff in there does work though...I may have misunderstood something about how ProcessLifecycleOwner worked, and whether we can use it effectively. It appears it is possible, I'll investigate but - with apologies - it won't be super high priority. In that sense if this is something you are interested in I'd be more than happy to take any reasonable PR

@mikehardy mikehardy reopened this Nov 2, 2023
@mikehardy mikehardy added platform: android help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. labels Nov 2, 2023
Copy link

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

@github-actions github-actions bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Nov 30, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2023
@mikehardy mikehardy reopened this Dec 15, 2023
@github-actions github-actions bot removed the Type: Stale Issue has become stale - automatically added by Stale bot label Dec 15, 2023
Copy link

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

@github-actions github-actions bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Jan 12, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help: good-first-issue Issues that are non-critical issues & well defined for first time contributors. platform: android Type: Stale Issue has become stale - automatically added by Stale bot
Projects
None yet
Development

No branches or pull requests

2 participants