Application Launch-Time to long

327 views Asked by At

I've a problem with the Application Launch-Time. If I start my app (launching main activity) it took around 3-4 seconds until the app is finally displayed. I removed everything from the onCreate method so it contains only setContentView(R.layout.activity_main) which sets a simple LinearLayout. There is no complex layout structure or other heavy code in the MainActivity.

For logging the launching time I used both the adb shell command which give me the following output:

12-06 11:40:06.395 918 939 I am_activity_launch_time: [0,78089240, de.package.package/.MainActivity,3724,3724]

and also TraceView:

enter image description here

I'm not really familiar with TraceView so I don't understand much of the output but the "bindApplication" part take a long time. I also imported some libraries in my gradle file which I need for the application, maybe they affect the Launch-Time:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    repositories {
        mavenCentral()
        jcenter()
    }

    defaultConfig {
        applicationId "de.watado.watado"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.android.support:support-v4:25.0.1'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.balysv:material-ripple:1.0.2'
    compile 'com.google.android.gms:play-services-location:9.8.0'
    compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.google.maps.android:android-maps-utils:0.4.4'
    compile 'com.crystal:crystalrangeseekbar:1.1.1'
    compile 'com.android.support:cardview-v7:25.0.1'
}

Does anyone know why my application need so long to be displayed?

EDIT: MainActivity

public class MainActivity extends FragmentActivity implements View.OnClickListener,
                                                          ViewPager.OnPageChangeListener{

private TextView tvHome, tvCat, tvSearch, tvLike;
private int currentPos = 0;
private ViewPager pager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public void onClick(View view) {
    switch (view.getId()){
        case R.id.textView_home:
            changeButtonState(-1);
            break;
        case R.id.textView_categories:
            changeButtonState(0);
            break;
        case R.id.textView_search:
            changeButtonState(1);
            break;
        case R.id.textView_like:
            changeButtonState(2);
            break;
    }
}
}
2

There are 2 answers

3
Tomasz Czura On

Could you post your custom Application class and first activity? Also, please check run time in release mode - debug mode can take longer because of e.g. InstantRun

2
Sanket Berde On

Possible reasons:

  1. Using Multidex increases the launch time.

  2. If you clear data, and launch the app, it will take longer because of the ART runtime will compile the app first.