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

jOOQ 3.10 Supports JPA Attribute Converter
One of the cooler hidden features in jOOQ is the JPADatabase, which allows for reverse engineering a pre-existing set of JPA-annotated entities to generate jOOQ code. For instance, you could write these...

Observer Pattern in Java.
As I was going through the different source code files of the Java Util package, I found the implementation of the Observer Pattern ( see the Gang of Four books for more information on this pattern) in...

Constructor in Java
A constructor is a particular type of method that is used to initialise the object. The constructor is invoked at the time of object creation. It constructs the values, i.e. provides data for the object...

10 Ways My Life Changed When I Learned To Code
1. I have freedom to make my own schedule. 2. I earn more, but work fewer hours. 3. I can say “no” to job offers. 4. People come to me asking if I can work for them. 5. I never have to...

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...
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