O primeiro início do aplicativo para Android é muito lento e o systrace mostra 30 segundos de bindApplication
Atualmente, estou desenvolvendo um aplicativo Android e tentando melhorar o horário de início. Para fazer isso, estou usando oSystrace ferramenta.
A primeira vez que executo o aplicativo (logo após a instalação), leva aproximadamente 40 segundos para iniciar e recebo esse rastreamento:
Como você pode ver, há uma tag roxa clara de 30 segundos com o títulobindApplication
.
Depois disso, fecho o aplicativo (retirado das atividades recentes) e o reabra. Desta vez, obindApplication
tag tem apenas 4 segundos:
Meu palpite aqui é quebindApplication
está relacionado de alguma forma ao trabalho pesado noonCreate
Método App, mas não vejo como isso poderia acontecer. Apenas no caso de ajudar: no meuonCreate
Inicializo as seguintes bibliotecas: Parse, Crashlytics, Timber, ParseFacebookUtils e Google Analytics.
EDITAR:
Aqui está o código da subclasse do aplicativo:
public class MyApp extends Application {
private Tracker tracker;
@Override public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Trace.beginSection("MyApp");
}
Fabric.with(this, new Crashlytics());
// Parse setup
Parse.enableLocalDatastore(this);
ParseObject.registerSubclass( ... );
Parse.Configuration.Builder parseConfigBuilder = new Parse.Configuration.Builder(this).applicationId(
getString(R.string.parse_application_id))
.server(getString(R.string.parse_server_url));
if (BuildConfig.DEBUG) {
// add logs
Timber.plant(new DebugTree());
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
parseConfigBuilder.addNetworkInterceptor(new ParseLogInterceptor());
}
Parse.initialize(parseConfigBuilder.build());
ParseFacebookUtils.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
AnalyticsManager.getInstance().init(this);
AnalyticsManager.getInstance().debugMode(BuildConfig.DEBUG);
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().
detectAll()
.penaltyLog()
.build());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Trace.endSection();
}
}
/**
* Gets the default {@link Tracker} for this {@link Application}.
* @return tracker
*/
synchronized public Tracker getDefaultTracker() {
if (tracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
tracker = analytics.newTracker(R.xml.global_tracker);
}
return tracker;
}
}