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

Online Gaming apps for Android
Smart phones are very common these days. Android smart phones are what people are buying a lot. With the updated versions of android too, it is making mobile user friendly and very much extensive in use....

How To Setup development Environment Of Java?
After installation of JAVA, we need to setup 2 environment variables. First one is JAVA_HOME and second is Path. Below steps to set up Java environment to compile & execute Java programs from command...

JAVA - Object Cloning
JAVA - Object Cloning Is the way of creating the same copy of object without calling the class constructor. It means we can make any class object multiple times without calling its default constructor....

Spring - Dependency Injection (DI)
Spring - Dependency Injection (DI) DI is a framework which provides loose coupling in code. Here loose coupling means no hard coding of the object. Instead of hard coding, we will be injecting these object...

Class, Object and Methods in JAVA
Lesson-1: Class, Object and Methods of Java can be compared with body, heart and brain. Without these 3 things, Java does not exist. If you Google the above 3 items, you will find many definitions. But...
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