Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android appwide view overlay (HUD)

I want to overlay a view over my entire app, all activities included. Think of it as a HUD (Head Up Display) over my app. The app has multiple activities, including a tab activity and the HUD doesn't interact with the user in any way, it just displays information while letting the user interact with the app as she would normally. I want this HUD for debugging purposes so I (and others) can monitor app activity and state when the phone is not attached to a debugging machine (field testing).

How do I do add such a view?

I've tried using WindowManager.addView() like so:

        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
             LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
             WindowManager.LayoutParams.TYPE_APPLICATION,
             WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                  | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
             PixelFormat.TRANSLUCENT);
        windowManager.addView(hudView, lp);

But the HUD doesn't seem to persist in the foreground when I launch new activities it simply disappears.

like image 455
acoward Avatar asked Nov 14 '22 03:11

acoward


1 Answers

I know this is an old question, but I thought I'd answer anyway since this helped me out. I was trying to get an HUD running in an openGL game and this works perfectly for that.

Since you already have the HUD displaying using the window manager, all you need to do to keep it persistant between activities is to call windowManager.addView(hudView, lp); in each activity's onResume() method. Not sure what the memory implications are though (i.e. is the view being disposed of when the window manager removes it from the screen upon switching activities), but at least it will keep the HUD up throughout the entire app.

like image 76
Ben Baron Avatar answered Dec 09 '22 19:12

Ben Baron