LBoy
LBoy

Reputation: 71

WindowManager for all activities in an application

My end goal is to use WindowManager and add views to it that will persist across my entire app (without using TYPE_SYSTEM_OVERLAY that requires a special permission from the user in API >=23).

What I do currently is this:

  1. Register ActivityLifecyclerCallback when that app launches
  2. Add the views I want to persist to the windowManager and keep a list of them on the side.
  3. Every time an activity is resumed I do this:
    1. get the WindowManager of the current activity by calling currentActivity.getWindowManager()
    2. reinflate and recall wm.addView(..) to all the windows that were added before.

However, no matter what I do the windows never get added when calling addView, its like the window manager just ignores that call..

I am using TYPE_APPLICATION for the windows.

I tried using currentActivity.getSystemService(WINDOW_MANAGER) instead of currentActivity.getWindowManager()

Can anybody tell why?

Upvotes: 1

Views: 1159

Answers (1)

LBoy
LBoy

Reputation: 71

Contrary to all beliefs TYPE_APPLICATION_ATTACHED_WINDOW or TYPE_APPLICATION or anything that with the word APPLICATION in it (which makes sense by the way) is NOT the way to go.

I have no idea why and if a Google engineer is here to answer that would be great but the solution is to use TYPE_TOAST (?!?!?)

Also make sure you get a new WindowManager instance from the new activity when switching between activities so if you add windows or remove them it is a valid instance.

Thanks about it.. 4 hours wasted over naming conventions and lack of good documentation :)

Upvotes: 1

Related Questions