Android Doc.

 0    25 fiche    H3TM4N
Télécharger mP3 Imprimer jouer consultez
 
question język polski réponse język polski
Activity lifecycle
commencer à apprendre
onCreate() onRestart(): (Only called after onStop()) onStart() onResume() onPause() onStop() onDestroy()
Fragment lifecycle
commencer à apprendre
onAttach() onCreate() onCreateView() onActivityCreated() onStart() onResume() onPause() onStop() onDestroyView() onDestroy() onDetach()
onCreate() method
commencer à apprendre
It's the one method every activity must implement. The onCreate() method is where you should do any one-time initializations for your activity. For example, in onCreate() you inflate the layout, define click listeners, or set up data binding.
onStart() method
commencer à apprendre
The onStart() lifecycle method is called just after onCreate(). After onStart() runs, your activity is visible on the screen. Unlike onCreate(), which is called only once to initialize, onStart() can be called many times in the lifecycle of your activity.
Note that onStart() is paired with a corresponding onStop() lifecycle method. If the user starts your app and then returns to the device's home screen, the activity is stopped and is no longer visible on screen.
on Restart() method
commencer à apprendre
It is invoked after the activity has been stopped and prior to its starting stage and thus is always followed by onStart() when any activity is revived from background to on-screen.
on Resume() method
commencer à apprendre
invoked when the activity starts interacting with the user. At this point, the activity is at the top of the activity stack, with a user interacting with it. Always followed by onPause() when the activity goes into the background or is closed by the user.
onPause() method
commencer à apprendre
invoked when an activity is going into the background but has not yet been killed. It is a counterpart to onResume(). When an activity is launched in front of another activity, this callback will be invoked on the top activity (currently on screen).
onStop() method
commencer à apprendre
invoked whenthe activity isnot visible to the user. It is followed by onRestart() when the activity is revoked fromthe background, followed by onDestroy()when the activity is closed or finished, and nothing when the activity remains onthe background only.
Note that this method may never be called, in low memory situations where the system does not have enough memory to keep the activity’s process running after its onPause() method is called.
onDestroy() method
commencer à apprendre
The final call received before the activity is destroyed. This can happen either because the activity is finishing (when finish() is invoked) or because the system is temporarily destroying this instance of the activity to save space.
MVVM (Model View ViewModel)
commencer à apprendre
is the industry-recognized software architecture pattern that overcomes all drawbacks of MVP and MVC design patterns. MVVM suggests separating the data presentation logic(Views or UI) from the core business logic part of the application.
There are 2 ways to implement MVVM design pattern in Android projects: 1. Using the DataBinding library released by Google Using any tool like RxJava for DataBinding.
MVVM (Model)
commencer à apprendre
This layer is responsible for the abstraction of the data sources. Model and ViewModel work together to get and save the data.
MVVM (View)
commencer à apprendre
The purpose of this layer is to inform the ViewModel about the user’s action. This layer observes the ViewModel and does not contain any kind of application logic.
MVVM (ViewModel)
commencer à apprendre
It exposes those data streams which are relevant to the View. Moreover, it servers as a link between the Model and the View.
Jetpack Architecture Components in Android
commencer à apprendre
is a set of software components, libraries, tools, and guidance to help in developing robust Android applications.
Further, Architecture Components could be classified as follows: Room WorkManager, Lifecycle, ViewModel, LiveData, Navigation, Paging, Data Binding,
Architecture Components (Room)
commencer à apprendre
is Google's new persistence library designed to make it easier to build offline apps. It tries to expose APIs that can leverage the full power of SQL while still providing an abstraction layer for managing the data as Java objects.
Advantages of Room Component: Reduce boilerplate code Simplifies database access mechanism Easy to implement migrations Test-ability is high
Room sub-components (Entity)
commencer à apprendre
It is the annotated class for which the Room creates a table within the database. The field of the class represents columns in the table.
Room sub-components (DAO)
commencer à apprendre
(Data Access Object): It is responsible for defining the methods to access the database and to perform operations.
Room sub-components (Database)
commencer à apprendre
It is an abstract class that extends RoomDatabase class and it serves as the main access point to the underlying app’s relational data.
Architecture Components (ViewModel)
commencer à apprendre
is one of the most critical classes of the Android Jetpack Architecture Component that support data for UI components. Its purpose is to hold and manage UI-related data.
Moreover, its main function is to maintain the integrity and allows data to service during configuration changes like screen rotations.
Architecture Components (LiveData)
commencer à apprendre
LiveData is an observable data holder class. LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services.
Advantages of LiveData component: UI is updated as per the appropriate change in the data It removes the stopped or destroyed activities which reduce the chance of app crash No memory leaks as LiveData is a lifecycle-aware component.
Dependency injection
commencer à apprendre
Classes often require references to other classes. For example, a Car class might need a reference to an Engine class.
These required classes are called dependencies, and in this example the Car class is dependent on having an instance of the Engine class to run.
Dependency injection Hilt
commencer à apprendre
library for Android that reduces the boilerplate of doing manual dependency injection in your project.
Hilt provides a standard way to use DI in your application by providing containers for every Android class in your project and managing their lifecycles automatically. Hilt is built on top of the popular DI library Dagger.
Hilt application class
commencer à apprendre
All apps that use Hilt must contain an Application class that is annotated with @HiltAndroidApp.
This generated Hilt component is attached to the Application object's lifecycle and provides dependencies to it. Additionally, it is the parent component of the app, which means that other components can access the dependencies that it provides.
Inject dependencies into Android classes
commencer à apprendre
Once Hilt is set up in your Application class and an application-level component is available, Hilt can provide dependencies to other Android classes that have the @AndroidEntryPoint annotation:
Hilt currently supports the following Android classes: Application (by using @HiltAndroidApp) ViewModel (by using @HiltViewModel) Activity Fragment View Service BroadcastReceiver
Service
commencer à apprendre
is an application component that can perform long-running operations in the background. It does not provide a user interface. Once started, a service might continue running for some time, even after the user switches to another application.
Additionally, a component can bind to a service to interact with it and even perform interprocess communication. For example, a service can handle network transactions, play music, perform file I/O, or interact with a content provider.

Vous devez vous connecter pour poster un commentaire.