Android go to title + Handler

Source: Internet
Author: User

Android go to title

Add the following statement before setcontentview (R. layout. activity_main) of the activity.

Requestwindowfeature (window. feature_no_title );

 

 

You cannot enable network connection in the main thread for Android 4.0 or later. Otherwise, an exception is thrown. You need to obtain network data in the Child thread.

Handler has restrictions on the returned data. The simplest way is to define a global variable. assigning values to global variables can solve the problem. Of course, this method may have some side effects. I am not very clear about the specific side effects.

 

New thread (New runnable (){

@ Override
Public void run (){
Try {
Newes = newsservice. getjsonlastnews (); // the most time-consuming function. newes is defined as a global variable to return data.
} Catch (exception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Message MSG = new message ();
Handler. sendmessage (MSG );
}
}). Start ();


 Handler = new handler (){
@ Override
Public void handlemessage (Message MSG ){
// Process data in the middle
}
};

 
 

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.