Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@0xZOne
Copy link
Member

@0xZOne 0xZOne commented Dec 8, 2021

Give the shared engine app a chance to take control of application lifecycle state events.

Related issues:
flutter/flutter#52456
flutter/flutter#94702
flutter/flutter#49950

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@chinmaygarde
Copy link
Contributor

The linked issues are un-prioritized. cc @blasten for guidance on is this is something we should do.

@0xZOne
Copy link
Member Author

0xZOne commented Dec 28, 2021

The linked issues are un-prioritized. cc @blasten for guidance on is this is something we should do.

In the add-to-app scenario, many applications choose the technical solution where multiple FlutterActivity shares the single cached engine.

When a new FlutterActivity attaches to the single cached engine and the previous FlutterActivity detaches from it, the sequence of app lifecycle events will be unexpected and cause the new FlutterActivity to be frozen. See flutter/flutter#49950 for details.

If we give the host application a chance to take control of the app lifecycle events, WidgetsBindingObserver.didChangeAppLifecycleState will be triggered correctly and the frozen issue also will be fixed.

@chinmaygarde
Copy link
Contributor

Ping @blasten for review.

@chinmaygarde
Copy link
Contributor

@blasten: You may be inundated to review requests. Is there anyone else I should redirect these reviews to?

@blasten
Copy link

blasten commented Jan 20, 2022

oh sorry, I had this PR opened in a tab.

* Give the host application a chance to take control of the app lifecycle events.
*
* <p>Return {@code false} means the host application dispatches these app lifecycle events, while
* return {@code true} means the engine dispatches these events.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we explain why anyone may want to do this? The more context, the better.

I left some areas to cover in flutter/flutter#94702 (comment)

Copy link
Member Author

@0xZOne 0xZOne Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we explain why anyone may want to do this? The more context, the better.

I left some areas to cover in flutter/flutter#94702 (comment)

    /**
     * Give the host application a chance to take control of the app lifecycle events to avoid
     * lifecycle crosstalk.
     *
     * <p>In the add-to-app scenario where multiple {@link FlutterActivity} shares the same {@link
     * FlutterEngine}, the application lifecycle state will have crosstalk causing the page to
     * freeze. For example, we open a new page called FlutterActivity#2 from the previous page
     * called FlutterActivity#1. The flow of app lifecycle states received by dart is as follows:
     *
     * <p>inactive (from FlutterActivity#1) -> resumed (from FlutterActivity#2) -> paused (from
     * FlutterActivity#1)
     *
     * <p>On the one hand, the {@code paused} state from FlutterActivity#1 will cause the
     * FlutterActivity#2 page to be stuck; On the other hand, these states are not expected from the
     * perspective of the entire application lifecycle. If the host application gets the control of
     * sending {@link AppLifecycleState}, It will be possible to correctly match the {@link
     * AppLifecycleState} with the application-level lifecycle.
     *
     * <p>Return {@code false} means the host application dispatches these app lifecycle events,
     * while return {@code true} means the engine dispatches these events.
     */
    boolean shouldDispatchAppLifecycleState();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@0xZOne 0xZOne force-pushed the task/takeoverlifecycle branch from 5fe6d8b to bbf9039 Compare January 21, 2022 08:24
@0xZOne 0xZOne requested a review from blasten January 21, 2022 08:45
@chinmaygarde
Copy link
Contributor

@blasten This seems to be good for another review attempt.

@chinmaygarde
Copy link
Contributor

Ping @blasten

*
* <p>Return {@code false} means the host application dispatches these app lifecycle events,
* while return {@code true} means the engine dispatches these events.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you like to contribute with an e2e test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blasten Thank you for your reply.

Does the e2e test block this PR? I may be available to write the e2e test after two weeks.

BTW, It would be nice if there was an e2e test guideline. :)

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chinmaygarde chinmaygarde added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 3, 2022
@fluttergithubbot fluttergithubbot merged commit 0044616 into flutter:main Mar 3, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

customer: alibaba platform-android waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants