Analysis of why the toast in Android doesn't show up

Source: Internet
Author: User

When you find out that your toast's Show method is actually executed, but not displayed in the interface,

There may be two points in the wrong place:

1.Context Context object has a problem, not the current context object or something;

2.message (that is, the problem that the toast will display) has a problem, and the message may end with "".

If neither of these issues is wrong, consider that Android does not allow UI changes in child threads

To solve this problem, it is easy to display the toast by passing the received data through handler in a child thread.

For example, when implementing the feedback page.

This is the code in the child thread when the feedback is successful, and the feedback failure is not written.

New= success_send;handler.sendmessage (message);

The following is the data obtained in the handler

PrivateHandler Handler =NewHandler () { Public voidhandlemessage (android.os.Message msg) {String text=NULL; Switch(msg.what) { CaseContent_null:text= "Feedback content cannot be empty";  Break;  CaseSuccess_send:text= "Thank you for your feedback"; default:                 Break; } Toast Toast= Toast.maketext (feedbackactivity. This, text, Toast.length_long); Toast.setgravity (Gravity.top,0, 0);            Toast.show ();        LOG.D (TAG, text);    }; };

Analysis of why the toast in Android doesn't show up

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.