A panel to visually represent a Frontend. Panels are intended to be presented to the user by the system UI, which does this by attaching the IviFragment returned by createInitialFragment to its layout. The created fragment will internally instantiate a ViewModel (FrontendViewModel) with a reference to this panel.
The system UI may choose to show and stop showing the panel more than once. E.g., a panel may be temporarily removed from the system UI if a similar panel with higher priority is offered to the system UI. Each time, a new fragment, along with its ViewModel, is created and destroyed. As such, it's important to consider whether data should be stored in the panel or the ViewModel. Data that is solely used by the fragment's view typically belongs in in the ViewModel, but note that it will be cleared when the panel is removed and presented again. Data that is important to persist should be kept in the panel instead.
Service connections for presenting data are commonly in the ViewModel rather than the panel to avoid keeping services alive for panels that are not presented. (Note that if the service requested in the ViewModel is already alive, creating another connection to it is a cheap operation.) It can however be beneficial for the panel to ask for a service connection in its constructor, allowing the service connection to be created by the Frontend and thus stay alive after the panel is destroyed. This allows panel contents to be populated immediately upon showing and is important when a service call must be performed upon the destruction of the panel or ViewModel, as those calls may fail when the service is closed as a result of the panel's or ViewModel's destruction. Similarly, if a call is needed when the panel is removed, it is not sufficient to perform it within ViewModel.onCleared because the ViewModel may never have been created during the panel's lifespan.
The panel starts as detached with the lifecycle in Lifecycle.State.CREATED. The lifecycle changes state to Lifecycle.State.STARTED when it is attached to the system UI. The panel can be detached and then attached again.
If the panel is dismissed or removed from the frontend, its lifecycle transitions to Lifecycle.State.DESTROYED after which it may not be added to a frontend again.