Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an activity window stay always on top

I want to create an activity that stays always on top (like the modal windows or task manager in Windows) of the others activities. How can I do this on Android? Thanks

like image 691
Alex Avatar asked Nov 27 '10 11:11

Alex


People also ask

How do you make a window always on top?

Just press CTRL + SPACE on whatever window you want to stay on top.

How do I keep my activity screen awake?

As described above, if you want to keep the screen on in your activity, use FLAG_KEEP_SCREEN_ON . One legitimate case for using a wake lock might be a background service that needs to grab a wake lock to keep the CPU running to do work while the screen is off.

How do I keep a tab on top?

To make the active window always on top, press Ctrl + Spacebar (or the keyboard shortcut you assigned). Press the keyboard shortcut again to disable “always on top” for the active window.


2 Answers

You can use the following code in the overridden onStop method of your activity:

@Override
protected void onStop(){
    super.onStop();
    Intent intent = new Intent(this, ClassNameOfYourActivity.class);
    startActivity(intent);
}

Beauty problem: your activity will pop-up again if any other activity trying to claim the focus. So it's not a modal window.

And it's dangerous! You wont be able to handle the Android GUI, you'll be able to control only your application GUI. For instance, switching debug mode on-off, killing application (only over ADB), reaching system settings, etc. will be impossible. If you switch off the ADB and combine it with the auto start mechanism then you'll be in trap.

So you won't be popular if you share it with Play :)

like image 101
bdevay Avatar answered Oct 07 '22 12:10

bdevay


Depending on what exactly you are trying to do, you might be happy with windows that stay on top of other Activities.

Apps like Super Video client & Floating Notes are able to display floating windows above other activities. These questions might point you in the right direction:

  • Creating a system overlay window (always on top)
  • How to create always-top fullscreen overlay activity in Android
like image 24
Richard Le Mesurier Avatar answered Oct 07 '22 12:10

Richard Le Mesurier