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

Palindrome Number : Java Function
An easier way to find out whether a number is a Palindrome number or not. Eg. 121, 88, 12321 etc public boolean isPalindrome ( int n ) { int rev = 0, r; for( i = n; i > 0; i /= 10 ) { r...

Inheritance In Java
Inheritance: The process of getting properties and behaviors from one class to another class is called inheritance. Properties: Variables Behaviors: Methods The main purpose of the inheritance...
D

Deleted U.

1 0
0

Necessity of Theory and Practical in Computer Science.
Upon studying a subject both theory and practical are important. Usually many schools concentrate more on theory and the marks not on the practical. Other and opposite kind of people prefer practical...

Java Hash Map internal implementation
1.Hash Map internal implementation: In hash map it will create an array of table (to store the {Key,Value} pair) which is of type java.util.HashMap.EntryThe Entry object contains {hash, key, next, value}...
R

Java : Compile-time Versus Runtime optimization
While designing and development, one should think in terms of compile-time and run-time.It helps in understanding language basics in a better way.Let's understand this with a question below : What...
S
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