Enable Dialog in android Service

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.