1

I have a parent activity for all my activities (they are a lot) which also acts as broadcast receiver. After I get a broadcast I need to show a view on the bottom of the screen no matter on which activity I am. All activities have different layouts, drawer, frame, linear, relative. Any guides or solutions or suggestions on how should I achieve this behavior?

If they were all relative it would have been easy I guess. but now with the other ones, I'm kinda stuck

EDIT:

I solved the problem by inflating and adding a view on the WindowManager which allows me enough options to play with it without having to go and change any layouts. Although the answers would below would be nice in the long run I needed the simplest and fastest solution.

Bri6ko
  • 1,858
  • 1
  • 18
  • 29
  • Always on top fragment composed of a relative layout that acts as an overlay, that is attached to your receiver activity. When you receive the broadcast pop the image to the lower left part of the fragment. Not really sure if that will work though, just trying to think of something :P – zgc7009 May 07 '14 at 18:49
  • If they were all relative layouts I would not have been worried. But as I said there a are fragments with LinearLayout or FrameLayout, then there are activities also with LinearLayout, FrameLayout, DrawerLayout and there are a LOT. I'm supposed to go and change them one by one. I was wondering if there is some solution that would not make me go through every single one and set the layout to work. Something like add the view programmatically on some absolute position. – Bri6ko May 07 '14 at 18:59
  • 1
    That is what I am saying, in your your `parent activity` attach a fragment that will act as an always on top overlay. So that even when your other activities are active, it will be their overlay. It will be an empty relative layout that you can add your image to as you need to. All you would have to do on receiving is inflate the image in your fragment that is attached to the parent activity that is receiving the broadcast. – zgc7009 May 07 '14 at 19:02
  • Take a look at http://stackoverflow.com/questions/4481226/creating-a-system-overlay-window-always-on-top it kind of explains what I am saying. You will create a layout that will always be there, but you won't ever see it until you inflate the image from your receiver. – zgc7009 May 07 '14 at 19:06
  • mmm yeah, that sounds interesting, I'll give it a try. thx :) – Bri6ko May 07 '14 at 19:07

2 Answers2

0

Depending on how you have your project structured you have some different options. A lot of the time people tend to load layouts within a fragment and display them using the Actionbar or NavigationDrawer. The main FragmentActivity would be the ideal place to add any view that would need to overlay any of these fragments. However when you have many different activities you will need to handle this situation individually. In you parent activity class you can add the view dynamically to your activity layout. Just be sure that the top most node of your layout is a FrameLayout.

0

you can add a relative layout on all your layouts as shown

enter image description here

add a gone/visible toggle of alert layout in BaseActivity which all activities inherit from

ir2pid
  • 5,604
  • 12
  • 63
  • 107