[Android UI] Activate activity and Alertdialog within service

Source: Internet
Author: User

Start ACTIVITY Source: (Remember to add Intent.flag_activity_new_task)

New Intent (); Intent.setflags (Intent.flag_activity_new_task); Intent.setclass (Getapplicationcontext (), Filebrowseractivity. class); StartActivity (intent);  

Cause: If an external ACTIVITY context calls the StartActivity method, then the intent object must contain the FLAG_ACTIVITY_NEW_TASK flag, because the The activity to be created does not start with an existing activity (the task stack does not have this activity), it does not already exist, so it needs to be placed in its own separate task (i.e. create a new task in the task stack).

Start Alertdialog Source:

Alertdialog.builder Builder =New Alertdialog.builder (This); Builder.setmessage ("Do you accept files?")). Setpositivebutton ("Yes",NewDialoginterface.onclicklistener () {@OverridePublicvoid OnClick (Dialoginterface dialog,Int which) {}}). Setnegativebutton ("No", new Onclicklistener () {@ Override public void OnClick (Dialoginterface Dialog, Span style= "color: #0000ff;" >int which) {}}); Alertdialog ad = Builder.create (); ad.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); //ad.getwindow (). SetType ( WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); Ad.setcanceledontouchoutside (false ); // Click outside the area will not let dialog disappear Ad.show ();     

Plus permissions:<uses-permission android:name="Android.permission.SYSTEM_ALERT_WINDOW" />

[Android UI] Activate activity and Alertdialog within service

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.