How to make an activity window stay always on top

Alex picture Alex · Nov 27, 2010 · Viewed 29.2k times · Source

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

Answer

bdevay picture bdevay · May 28, 2013

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 :)