Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 220.127.116.11 release ready!
Owner and Founder. Opencart
Lifecycle is an Abstract class in Android which attaches with Application lifecycle. It helps to manage the lifecycle event of the activity or fragment. It helps to manage the state of the application event. We can also define multiple lifecycle events on the same method using annotated. We can manage the lifecycle event like onCreate, onStart and onStop in our custom observer class.
An event is the lifecycle event that has been triggered by a lifecycle change (such as resuming an activity). In our classes, we can implement callbacks for each of these events so that we can handle lifecycle changes. The arch.lifecycle package provides an Annotation for us to use which means we can annotate the methods within our class which should be triggered upon certain lifecycle events.
Add a dependency in your build.gradle
In this example, we going to implement lifecycle observer in our MainActivity class. To implement Custom Lifecycle observer we are going used getLifecycle() method in onCreate() method which return Lifecycle instance of the activity and we will use an addObserver method where we have passed the object of our custom MainActivityObserver class
To attach event with the method all we have to do just add annotation with the event.
MainActivityObserver implement LifecylceObserver interface. We can also handle multiple lifecycle events within the same annotated method, this allows us to trigger a specific method based on multiple lifecycle events being triggered:
Hope this blog helps you to understand the lifecycle observer feature and write lean code for application lifecycle event.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
These guys really know what they are doing and I genuinely mean it. This is a second project that we've worked with them and I'm sure it won't be the last. They've worked their butts off to fulfill every request I have made and made it perfect.
If you still considering of using their services I suggest you ask for Sushil and he will put "all the ducks in the row" for you :)
Great job guys, thanks again for everything.
Best choice for your e-store
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.