Home > Mobile >  Ask questions about the interface
Ask questions about the interface

Time:09-15

Public class CameraComponent implements LifecycleObserver {

.

@ OnLifecycleEvent (Lifecycle. Event. ON_RESUME)
Public void initializeCamera () {
If (camera==null) {
GetCamera ();
}
}

.
}

Tutorial in the code, after receiving the ON_RESUME event, in this class will perform initializeCamera () to initialize the camera, but LifecycleObserver is not a interface, the interface is not without specific implementation?
Why this interface can put the news spread to come over?
If @ OnLifecycleEvent (Lifecycle. Event. ON_RESUME) this coming, why can coming, @ beginning Java annotations, isn't it? Used to generate javadoc, why can send messages?
Beginners, a great god laughed

CodePudding user response:

https://www.runoob.com/w3cnote/java-annotation.html

CodePudding user response:

reference 1/f, set up green _ response:
https://www.runoob.com/w3cnote/java-annotation.html

To be honest, true not understand (? _? And there, and I feel this example doesn't matter much. (? _?

CodePudding user response:

Annotations are not used to generate javadoc, also can generate Java classes or Java code,
Simple to understand is that the annotation id you registered a Lifecycle. Event. ON_RESUME observation of events, when the activity of the resume, make ON_RESUME Event, observe this Event because of you, at this time will be executed initializeCamera method, activit supportactiviy onresume operation is done, specific can refer to https://developer.android.com/topic/libraries/architecture/lifecycle

CodePudding user response:

You must first understand the LifeCycle is stem what of, it is used to monitor the life cycle, reduce the coupling of the code, Android is the Jetpack components in it

CodePudding user response:

Learned so many days, gradually produced their own understanding, I said, easy to understand, is the callback interface, is A function pointer, such as A class A, there is A interface, then A class must be will have A place to call this interface, if the B class implements this interface, so at A certain time, the realization of A class is automatically invoked the B class function, that is mean.

CodePudding user response:

OnLifecycleEvent annotations to register at start-up time, means that you focus on ON_RESUME event, there will be a collection, add to the current class, then ON_RESUME event occurs, will inform to all registered the class,
  • Related