Call toast and dialog in not an activity class

Source: Internet
Author: User

Sometimes we need to deal with some logic in the non-activity class, Show the Toast dialog box or pop a dialog, but there is no way to invoke these two in non-activity, and if necessary, consider passing the context, but it's too much trouble. There is another easy way to do this, and that is

Declare a static object in the activity where you want to display toast or dialog: public static mainactivity mactivity; and then in the OnCreate method inside the initialization of a sentence: Mactivity=this; This is the time to invoke the Toast method in other classes.

Call toast and dialog in not an activity class

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.