lifecycle

Flutter: Override widgets/components to get access to events alvin November 11, 2019 - 6:52pm

As a brief “note to self,” when you need to get access to Flutter widget events that you normally can’t access, override the widget to access lifecycle-related events like initState() and dispose() so you can access them. For example, this image (that comes from this URL) shows how to gain access to those lifecycle methods for a Flutter Drawer. You can do this with any component/widget — and you can also make the code more generic by passing in child widgets — and you can also mix in WidgetsBindingObserver and then use didChangeAppLifecycleState to gain access to more events.

When is the Android Fragment onCreateOptionsMenu method called?

Android FAQ: When is the Android Fragment onCreateOptionsMenu method called?

I was just working through a problem with an Android Menu and MenuItem, and added some debug code to the methods in my Android Fragment, and found that the onCreateOptionsMenu method is called after onStart. I didn’t put Log/debug code in every activity lifecycle method, but for the ones I did add logging code to, the specific order of the fragment method calls looked like this:

Understanding the methods in the Scala/Akka Actor lifecycle

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.4, “Understanding the methods in the Scala/Akka Actor lifecycle.”

Problem

You’re creating more complicated actors, and need to understand when the methods on an Actor are called.

Solution

In addition to its constructor, an Actor has the following life-cycle methods: