UrbanPro
true

Learn Android Application Development Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Android : Application Launch time improvements.

Gaurav Bansal
10/01/2017 0 0
For any standard android application, below 3 components play important roles to show 1st interface to user, so that he/she can interact with the app.
1. Custom Application class : Intialize the components which are going to be used for the all application components such as activities or views.
2. Splash Screen : It is the first UI which is displayed to the user, in the background of which, we initialize those components which are required for Main Activity (mentioned below) to show data
3. Main Activity : This is the home screen where major data is displayed using views and fragments.
To avoid delay in Launch, we can consider below few fixes.
a) There should be minimal functions in onCreate() method of above 3 components. Although when we check the time taken in onCreate() to be completed, it shows less time, but the component which you have initialised, will take some time to give result e.g. inflating layouts or initialising a third party SDK.
b) Instead of writing initialisation of 3rd party SDKs in your Application class, put them whenever they are first needed. e.g. Facebook or Google Login SDKs
c) Move the loader or inflater related to UI in your Main Activity instead of Application class as during app initialisation we are not showing any UI e.g. Notification count to show the bubble in Main Activity
d) Do the heavy work on the thread which are neither related to UI nor for immediate requirement. a thread can be started in Application class too if required.
e) In general, Splash is launched and we launch main activity after a certain time in Handler object using postRunnable. Instead of that we have to do heavy task in thread and on completion of that thread, we have to launch the Main Activity on Main thread as below:
Thread splashSetupThread = new Thread(new Runnable() {
    @Override
    public void run() {
 
    //Here do all the work not related to UI
    //after finish launch home screen in main thread as below
 
    runOnUiThread(new Runnable() {
    @Override    public void run() {
        launchHomeScreen();
    }
});
 
F) There can be some UI elements in the Main Activity which can be shown after main UI component is shown e.g. A mini player in a Music application can be displayed once the songs and albums are displayed to the user. So do not write the code of those UI elements into the onCreate of Main Activity , instead write them in onWindowFocusChanged() as below:
 
@Overridepublic void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if(onCreateCalled && hasFocus) {
        onCreateCalled = false;
        //write UI element inflation code
    }
}
 
If above steps are followed then certainly launch time will be reduced.

Question ? Please comment !!!
0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Why we need to learn Programming languages?
Language is medium for communication. If two parties like to communicate or exchange the thoughts they must know a language. Language should be understandable by both the Parties. For example A wants to...

Migration from other languages to Salesforce
Anyone can easily migrate from other language to Salesforce. People must have skills to understand business logic.

Java8 Filters and collectors
Lets say we have collection of strings and we would like to filter (remove) out certain strings from collection. We could achive the same in java 7 and earlier versions import java.util.ArrayList; import...

Why We Should Go With Java?
Java is widely used in the Desktop application, web application, mobile development, games etc. Java is an object-oriented programming language. Its follow all the oops concept Like Object, Class,...
B

Bhupendra Patidar

0 0
0

Method Overloading vs Method Overriding
1. Method Overloading: Method overloading means a same method with same name can have different implementations/body by changing one of the follwing thing: 1) Number of Parameters 2) Order of Parameters 3)...
X

Looking for Android Application Development Training Classes?

The best tutors for Android Application Development Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Android Application Development Training with the Best Tutors

The best Tutors for Android Application Development Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more