Enable Dialog in android Service
In ServiceThe Dialog pop-up method is the same as that of the Dialog pop-up method in the Activity. However, after the activity is finished, the dialog will also be closed, and it is attached to the activity. In the Service, there is no interface for the Service. The Dialog pop-up Dialog is displayed. What does it attach?
First, let's see how the dialog box pops up in Service:
Dialog = new AlertDialog. builder (ctx ). create (); dialog. getWindow (). setType (WindowManager. layoutParams. TYPE_SYSTEM_ALERT); dialog. show (); Window window = dialog. getWindow (); window. setContentView (R. layout. exit_dialog); Button OK = (Button) window. findViewById (R. id. sure); (TextView) window. findViewById (R. id. prompt_context )). setText (msg); OK. setOnClickListener (new View. onClickListener () {public void onClick (View v) {// destroy all ActivitystopSelf (); ExitApplication. getInstance (). exit () ;}}); Button cancel = (Button) window. findViewById (R. id. cancel); cancel. setOnClickListener (new View. onClickListener () {public void onClick (View v) {dialog. cancel () ;}}); dialog. setCancelable (false );
There is such a sentence:
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
This setting of dialog is global. The system dialog box is displayed on any interface.
However, when my app exits, the Service continues to run and the dialog is not expected to pop up. How can this problem be achieved?
Awaiting research!