Is it easier to manage app lifecycle with Flutter than with Java?

93 views
Skip to first unread message

Jack J

unread,
Jul 28, 2018, 10:58:41 PM7/28/18
to Flutter Dev
Using traditional way of development we have to write code that will preserve state of application after device orientation changed, in case of another application pop up... There a several lifecycle methods and a lot of additional code you may need to write. Is it the same way in Flutter or they invented something about it ?

Ryan Gonzalez

unread,
Jul 28, 2018, 11:33:30 PM7/28/18
to Jack J, Flutter Dev

Flutter draws everything by itself, and it uses an entirely different, cross-platform development model. Therefore, there's no need to deal with things like the Activity Lifecycle, because nothing like that really even exists in the Flutter world.

On July 28, 2018 9:58:44 PM Jack J <fsn7...@gmail.com> wrote:

Using traditional way of development we have to write code that will preserve state of application after device orientation changed, in case of another application pop up... There a several lifecycle methods and a lot of additional code you may need to write. Is it the same way in Flutter or they invented something about it ?

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian Hickson

unread,
Jul 28, 2018, 11:50:32 PM7/28/18
to Ryan Gonzalez, Flutter Dev, Jack J
Although you do still have to handle saving state for the case of the user leaving the app then coming back.
--

--
Ian Hickson

😸

Jack J

unread,
Jul 29, 2018, 12:23:31 AM7/29/18
to Flutter Dev


On Sunday, July 29, 2018 at 7:50:32 AM UTC+4, Ian Hickson wrote:
Although you do still have to handle saving state for the case of the user leaving the app then coming back.

Ian Hickson

😸

 Do you mean when you completely closing the app ?

Matt Carroll

unread,
Jul 29, 2018, 12:31:24 AM7/29/18
to fsn7...@gmail.com, Flutter Dev
Hi Jack,

Even when using Flutter, developers need to be conscious of associated lifecycle events, both for Android and iOS.

Android tends to be the greater concern because Android often destroys Activitys while retaining the application process, whereas iOS tends to either retain the whole application or kill the whole application.

You asked about Android.  In Android, Flutter is just a custom View that takes up the entire screen within an Activity.  That means that when the Activity is backgrounded, if Android evicts that Activity then the FlutterView is also destroyed.  When the FlutterView is destroyed, the data within your Flutter UI is also destroyed.  Therefore, you must make sure to persist whatever data you want to survive Activity and application eviction.

This is unavoidable because Flutter runs within an Android Activity and therefore Flutter is subject to all the same lifecycle concerns as a traditional Activity.

You might want to look into using an Android plugin to send your data from Flutter to SharePreferences.  Then when your FlutterView is recreated, you can pull the data out of SharedPreferences and send it back into your recreated FlutterView.

--

Jack J

unread,
Jul 29, 2018, 3:54:07 PM7/29/18
to Flutter Dev
Got it, thanks.
Reply all
Reply to author
Forward
0 new messages