desusai7 / lifecycle_events

Sample Flutter Plugin to demonstrate how FlutterFragmentActivity and FlutterActivity get attached to the FlutterEngine when running on Android Platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lifecycle_events

Sample Flutter Plugin to demonstrate the differences in how FlutterFragmentActivity and FlutterActivity get attached to the FlutterEngine when running on the Android Platform.

Description of the issue

I am registering for the ActivityLifeCycleCallBacks in the onAttachedToEngine of the Android Implementation of my Flutter Plugin as shown here

And I am printing out some debug statements in the ActivityLifeCycleHandler to demonstrate the issue as shown here

To observe the issue, run the app on the Android platform with MainActivity extending FlutterActivity as shown below, then you will observe that both onActivityStarted and onActivityStopped are properly triggered whenever the Application is moved background and foreground as shown in the image attached below:

image

And when we change the MainActivity to extend FlutterFragmentActivity and then we can observe that onActivityStarted is not triggered on the initial launch of the application, but from then the callbacks are triggered perfectly fine.

image

I am kind of wondering if the reason why the onActivityStarted is not triggered on the initial launch of the application when the MainActivity is extending FlutterFragmentActivity is because the FlutterFragmentActivity got attached to the FlutterEngine even before my FlutterPlugin got attached to the engine.

But however in the case of MainActivity extending FlutterActivity the Activity seems to be getting attached to the FlutterEngine always after the FlutterPlugin got attached to it.

Can we ensure that the process of activity getting attached to the engine is always done in a particular way irrespective of what type of activity is being extended by MainActivity to have a predictable and proper result?

I would prefer FlutterFragmentActivity also to be attached to the FlutterEngine after all the FlutterPlugin's are attached to the FlutterEngine. (Obviously, I do not have the knowledge of why it is being developed this way, and I can be completely wrong as well)

Also, please let me know if there is a better way to deal with this problem !

About

Sample Flutter Plugin to demonstrate how FlutterFragmentActivity and FlutterActivity get attached to the FlutterEngine when running on Android Platform

License:Other


Languages

Language:Dart 44.3%Language:Java 25.2%Language:Objective-C 16.7%Language:Ruby 13.8%