Android Handler Help

Source: Internet
Author: User


==================== Problem Description ====================
The following purple code will cause the program to stop running, please help to solve, tell the reason for younger brother.
public void onconfigurationchanged (Configuration newconfig) {
Mnewconfig=newconfig;
Message message = new Message ();
Message.what = UpdateUi;
uihandler.sendmessage (message);
}
[Color= #CC99FF]
Private Handler Uihandler = new Handler ()
{
public void Handlemessage (Message msg)
{
if (Msg.what==updateui)
Onconfigurationchanged (MNEWCONFIG,MTMP);
}
};

[/color]
public void onconfigurationchanged (Configuration newconfig,int tmp) {
Toast.maketext (Conversationlist.this, "New onconfigurationchanged", Toast.length_long). Show ();
Super.onconfigurationchanged (Newconfig);
}
If Uihandler.sendmessage (message) is not executed, it is called directlyonconfigurationchanged (Configuration newconfig,int tmp)Instead, there's no problem.
==================== Solution 1====================
You have a dead loop like this, constantly calling onconfigurationchanged, the stack will be full, and the natural program will crash!
==================== Solution 2====================
You this is a dead loop that will onconfigurationchanged (mnewconfig,mtmp); Move to the message handler function, or onconfigurationchanged (mnewconfig,mtmp); Do not execute the uihandler.sendmessage (message);
==================== Solution 3====================
Isn't that a dead loop?

Android Handler Help

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.