Skip to main content

Posts

Showing posts from 2020
Observable how Observable works an Observable has three most important events/methods; let's discuss them one by one: onNext: Observable passes all items one by one to this method. onComplete: When all items have gone through the onNext method, Observable calls the onComplete method. onError: When Observable faces any error, it calls the onError method to deal with the error, if defined. Note that both onError and onComplete are terminal events, and if onError is called, then it ”
MutableLivedata Mutablelivedata Sets the value If there are active observers, the value will be dispatched to them. This method must be called from the main thread. postValue(): Posts a task to a main thread to set the given value. If you called this method multiple times before a main thread executed a posted task, only the last value would be dispatched. To summarize, the key difference would be: setValue() method must be called from the main thread. But if you need set a value from a background thread, postValue() should be used.
lateinit var and by lazy Lazy and Lateinit Here are the significant differences between lateinit var and by lazy { ... } delegated property: lazy { ... } delegate can only be used for val properties, whereas lateinit can only be applied to vars, because it can't be compiled to a final field, thus no immutability can be guaranteed; lateinit var has a backing field which stores the value, and by lazy { ... } creates a delegate object in which the value is stored once calculated, stores the reference to the delegate instance in the class object and generates the getter for the property that works with the delegate instance. So if you need the backing field present in the class, use lateinit; In addition to vals, lateinit cannot be used for nullable properties or Java primitive types (this is because of null used for uninitialized value); lateinit var can be initialized from anywhere the object is seen from, e.g. from inside a frame...
Build Types and Build Variants Build Types and Build Variants While building any Android application, we create various build types such as "debug" and "release". At the same time, we can create various product flavors for the same app, for example, the free product flavor for free users and the paid product flavor for the paid users. So, Android Studio provides a feature of Build Variants which can be thought of as a cartesian product of all your build types and all your product flavors. All you need to do is add various build types in your module-level build.gradle file and during development or production, you can simply choose the Build Variant you want to test or release.
View Model store View Model store -What it does actually? A ViewModelStore can be considered as a container that stores the ViewModels in a HashMap. Where the key is string value and value is the ViewModel being saved(ViewModelProvider uses a concatenation of the string_key + ViewModel class canonical name). A ViewModelStoreOwner is merely an interface. Any class that implements the getViewModelStore() defined by this interface becomes the owner of ViewModelStore. This class then maintains the ViewModelStore and should be responsible to appropriately restoring it when needed.