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
You can't. As this is defined in the Android system.
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 :)
You can't. As this is defined in the Android system.
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:
Follow the steps to achieve your requirement
- Create an activity which is going to be the top activity
Add the following code in the manifest
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Use the following code to get overlay permission from user
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this)) { new AlertDialog.Builder(this) .setTitle("Permission Request") .setMessage("This app needs your permission to overlay the system apps") .setPositiveButton("Open settings", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); startActivityForResult(myIntent, 101); } }) .setNegativeButton(android.R.string.no, null) .show(); } }
© 2022 - 2024 — McMap. All rights reserved.