Skip to content

App Host

petterp edited this page Aug 30, 2026 · 2 revisions

App-level global window (AppHost)

AppHost, from floatingx-app: the window follows the current foreground Activity and lives in the registry under its tag. This page covers black / white lists, the attach target, theming and the Java entry point.

What it is

AppHost attaches the window container to the current foreground Activity. On a page change the container is not destroyed and rebuilt — the same container is silently reparented into the new page, so the engine state, features, animations and content view never restart and the position does not jump.

floatingx-app registers the Activity tracker from a ContentProvider declared in its manifest, at process start. So install picks up the current foreground Activity whether you call it from Application.onCreate, a page's onCreate or even a Service — there is no setContext to call.

On a page rejected by the black / white list or a filter, the window is detached as a whole (onHostLost); when an allowed page comes back it re-attaches automatically, keeping the desired visibility and the state — you do not have to call show() again.

Full example

val control = FloatingX.install("music") {
    layout(R.layout.fx_card)
    anchor(FxGravity.CENTER_END, dy = 120f)
    margin(top = 24f, bottom = 24f)
    adsorb(FxAdsorb.Edges(setOf(FxEdge.START, FxEdge.END), halfHide = FxHalfHide(0.3f)))
    persist(FxSpStorage(app))
    enableLog("Fx-demo")
    appHost(app) {
        // pass a Class, not a class name: matched with isInstance, so subclasses are hit too
        blacklist(SplashActivity::class.java)
    }
}
control.show()

The braces of appHost(app) { … } are an AppHost.Builder; every switch below goes in there.

Black / white lists and filters

appHost(app) {
    blacklist(SplashActivity::class.java)          // Class: matched with isInstance, subclasses are hit too
    blacklist("com.x.YActivity")                   // String: exact fully-qualified class name
    whitelist(MainActivity::class.java)            // with a whitelist, only whitelisted pages show it
    filter { activity -> !activity.isFinishing }   // your own rule, may be called several times
}
Entry point Matching
blacklist(vararg Class<out Activity>) Matched with isInstance, so listing a superclass hits its subclasses (#221)
blacklist(vararg String) Exact fully-qualified class name
whitelist(vararg Class<out Activity>) / whitelist(vararg String) With a whitelist, only whitelisted pages show it
filter(AppActivityFilter) Your own rule; may be called several times and all must pass (a fun interface, so Java can use a lambda)

Attach target

appHost(app) { attachTo(AppAttachTarget.CONTENT) }
Value Meaning
AppAttachTarget.DECOR Default. The Window's DecorView, which makes dragging truly full-screen, unaffected by the status bar, navigation bar or AppBar
AppAttachTarget.CONTENT android.R.id.content, so the window only covers the content area

Switch to CONTENT only when you want the window confined to the application view area.

Theme

The content of an app-level window is created with the Application context, and Material components (MaterialCardView and friends) need a Material theme — a plain Application context crashes them. Give the host a theme:

appHost(app) { theme(R.style.Theme_App) }

Which Activity it is attached to

val activity = control.attachedActivity   // FxControl extension from floatingx-app; null while detached

Java builder

FxConfig config = FxConfig.builder(FxContent.layout(R.layout.fx_card))
        .anchor(FxGravity.BOTTOM_START, 24f, 120f)
        .margin(16f, 16f, 16f, 16f)
        .adsorb(new FxAdsorb.Edges(EnumSet.of(FxEdge.START, FxEdge.END), new FxHalfHide(0.3f), true))
        .gesture(FxGesture.LongPressToDrag)
        .storage(new FxSpStorage(app))
        .enableLog("Fx-java")
        .build();
AppHost host = AppHost.builder(app)
        .blacklist(SplashActivity.class)
        .filter(activity -> !activity.isFinishing())
        .build();
FxControl control = FloatingX.install("java-app", config, host);
control.show();

The Kotlin DSL entry points are @JvmSynthetic, so Java goes through FxConfig.Builder + AppHost.Builder; AppActivityFilter is a fun interface and takes a lambda directly.


Back to Home · Related: Getting Started · Configuration · System Host

Clone this wiki locally