Android Fragment onCreateView vs. onActivityCreated

If your view is static, then moving any code to the onActivityCreated method is not necessary. But when you – for instance, fill some lists from the adapter, then you should do it in the onActivityCreated method as well as restoring the view state when setRetainInstance used to do so. Also accessing the view hierarchy … Read more

Detect if the application in background or foreground in swift

[UIApplication sharedApplication].applicationState will return current state of applications such as: UIApplicationStateActive UIApplicationStateInactive UIApplicationStateBackground or if you want to access via notification see UIApplicationDidBecomeActiveNotification Swift 3+ let state = UIApplication.shared.applicationState if state == .background || state == .inactive { // background } else if state == .active { // foreground } switch UIApplication.shared.applicationState { case .background, … Read more

onNewIntent() lifecycle and registered listeners

onNewIntent() is meant as entry point for singleTop activities which already run somewhere else in the stack and therefore can’t call onCreate(). From activities lifecycle point of view it’s therefore needed to call onPause() before onNewIntent(). I suggest you to rewrite your activity to not use these listeners inside of onNewIntent(). For example most of … Read more

What determines the lifecycle of a component (object graph) in Dagger 2?

As for your question What determines the lifecycle of a component (object graph) in Dagger 2? The short answer is you determine it. Your components can be given a scope, such as @Scope @Retention(RetentionPolicy.RUNTIME) public @interface ApplicationScope { } @Scope @Retention(RetentionPolicy.RUNTIME) public @interface ActivityScope { } These are useful for you for two things: Validation … Read more

Automatically log Android lifecycle events using ActivityLifecycleCallbacks?

I don’t have any firsthand experience but judging from the API you can just write your own class that implements the Application.ActivityLifecycleCallbacks interface and register that class on the provided Application class instance getApplicaton().registerActivityLifecycleCallbacks(yourCustomClass); This class will receive the same callbacks as your individual activities. Good luck. PS. This is API level 14 btw, so … Read more