Android task manager or system dialog

社会主义新天地 提交于 2019-12-30 13:49:37

问题


I would like to know is there a way to get events while displaying a System dialog (Such task manager, shut down alert,...).

I can close the system dialogs from my activity through intent like below

Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);

But in my code I need to know a system dialog is shown over the screen (They can be Task manager/ Shut down dialog ...), so that I can invoke the above code for closing it.

I searched for intent filters nothing found.


回答1:


put below method in your Actvity and check recent app dialog close automatically.

public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

        Log.e("Focus debug", "Focus changed !");

        if (!hasFocus) {
            Log.e("Focus debug", "Lost focus !");

            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            sendBroadcast(closeDialog);
        }
    }

Note: it only work for single Activity. not for all activity in your app.




回答2:


Use Broadcast-Receiver and place intent inside onreceive() method.Then register this receiver where you display your alert dialog. Then it automatically disable settings,recent apps button ----Nagesh



来源:https://stackoverflow.com/questions/15964108/android-task-manager-or-system-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!