TtiviActivityView
A View which displays any Activity as if it were on another display.
The view will display the background until a pendingIntent is given, and again once the launched activity has finished.
If set, onStartedCallback will be called as soon as the requested activity has been successfully launched, so before it is resumed. If onFinishedCallback is set, it will be called when the started activity has finished.
Note: Call isSupported at runtime to determine whether embedding is supported by the Android platform version. When this method returns false, using TtiviActivityView does not actually embed a view, but sends given PendingIntents as normally done in Android, switching away from the TomTom Digital Cockpit-based app. When the PendingIntent loads another activity, no control can be asserted over it: when it naturally finishes, Android is responsible to bring the user back to the initial app. As soon as the PendingIntent has been sent, the onFinishedCallback will immediately be called. The supported versions are currently SDK 28 (8.1), SDK 29 (9), SDK 30 (10), SDK 31 (11), SDK 32 (12).
Note: Embedding an activity from the same Android package as the activity containing TtiviActivityView causes inconsistent behaviour of IME (software keyboard) due to focus conflicts on Android 12. It is therefore recommended to only use TtiviActivityView to display activities from other packages.
Note: TtiviActivityView requires a background to be set. It uses a SurfaceView to render any activity. SurfaceViews render content outside of the app's view tree. The ordering is as follows, with the user looking from the first group, down to the last one:
Surfaces with
ZOrderOnTopflagApplication UI's view tree
Surfaces with
ZOrderMediaOverlayflagSurfaces with no flags
Multiple Surfaces inside a group are seemingly rendered in creation order. This ordering requires the window manager to poke a hole through the view hierarchy to reveal the surfaces below. The surface used to render the user Activity might not always be filled, and therefore, to prevent visual leakage of other Surfaces, an opaque background is required to always ensure visual consistency.
The background must be a solid color, set via either:
The
backgroundXML attribute.By directly calling setBackground with a ColorDrawable.
By calling setBackgroundColor.
Alpha channel is not supported: the view must be opaque. Alpha level changes to the view are ignored.
Note: No control is asserted over the lifecycle of the opened activity. When closing the view, the activity might survive and be brought to front when the view is reopened.
Note: Robolectric does not support the hidden APIs used to achieve some features, which makes TtiviActivityViews only partially accessible from Robolectric-based tests.
Note: onPanelExitAnimationStarted does not get called automatically. Use callOnExitAnimationStartedForChildViews to call this method for all child views of a ViewGroup.
Note: Some device configuration changes (such as changing screen orientation) cause all the views, including the activity view to be destroyed and created again. In order to allow the activity launched in the activity view to be properly restored, a part of activity view has to be preserved during configuration change. To allow that, create an instance of TtiviActivityViewStateHolder, store it outside of view hierarchy (for example, in a ViewModel) and pass it via either setStateHolder method or via the stateHolder xml attribute. When the TtiviActivityView instance is not needed anymore, call TtiviActivityViewStateHolder.release to clean the stored state and avoid memory leaks.
Properties
Callback invoked when the started activity has finished.
Callback invoked in onStarted when an activity, specified by pendingIntent, has successfully started or resumed after configuration change.
PendingIntent to launch an embedded activity. No control is asserted over the lifecycle of the started activity.
Functions
This should be called, before the dismissal of the panel containing this is started.
Sets the packageToAllowedPackagesMap for embedded applications.
elevation changes must be applied separately to the activity view.
Provides a state holder instance. The state holder should be preserved when the views are recreated during configuration change and passed to the new instance of TtiviActivityView.
visibility changes must be applied separately to the activity view.
Inherited functions
Sets the allowedPackages for embedded applications. See also TtiviActivityView.setAllowedPackageNames.
Provides a TtiviActivityViewStateHolder instance to TtiviActivityView. See also TtiviActivityView.setStateHolder.