Android app startup Speed Optimization

Source: Internet
Author: User

As more and more functions are being developed for Android applications, the startup speed is getting slower and slower. Is there a way to make your application start faster?

Methods are developed by humans. Let's talk about my implementation methods:

1. Move the content initialized in oncreate to the thread for initialization and loading.

2. After Initialization is complete, send a message through handler,

3. After receiving the message from hander, initialize the complete interface.

With this idea, the interface can be quickly displayed, rather than a black screen.

Code prototype:

Public class mainactivity extends activity {

@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity_main); // set layout Layout

// Use a thread to load data asynchronously without blocking the interface.
New thread (){

@ Override
Public void run (){
// Todo auto-generated method stub
Super. Run ();
Initdata ();
}

}. Start ();
}

Private Final Static int msg_init_view = 0xa00;
Private Final handler = new handler (){

@ Override
Public void dispatchmessage (Message MSG ){
Switch (msg. What ){
Case msg_init_view:
Initview ();
Break;
Default:
Super. dispatchmessage (MSG );
}


}

};

Private void initdata (){
Try {
Thread. Sleep (5000); // It takes 5 seconds to simulate Data Loading
} Catch (interruptedexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
// The data loading is complete. You can update the interface.
Handler. sendemptymessage (msg_init_view );
}

Private void initview (){
// Refresh the todo Interface
}

}

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.