F
F
fspare2015-10-07 13:38:58
Android
fspare, 2015-10-07 13:38:58

Initializing an Android application - how to get rid of brakes at startup?

Hello!
Now he is engaged in the development of an android application, its essence is to save the user's location in a local log, so that he can then see where he was during the day.
Now my suspicions fall on the fact that this problem is most likely related to the fact that initialization is performed in a class that is inherited from MultiDexApplication in the onCreate method (that is, the UI thread is clogged.).
On the other hand, this initialization must be done before you start using the application (before you switch to some kind of activity).
Below is a piece of code from the App class. Maybe you can advise something?

@Override
public void onCreate() {
    super.onCreate();
    // инициализировать библиотеку для работы с кастомными шрифтами, назначить Roboto Regular по умолчанию
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                    .setDefaultFontPath("fonts/Roboto-Regular.ttf")
                    .setFontAttrId(R.attr.fontPath)
                    .build()
    );
    // инициализировать библиотеку для закачивания изображений из сети
    Fresco.initialize(this);

    App.context = getApplicationContext();
    // инициализировать автоматическую отправку изображений
    ACRA.init(this);
    // инициализировать схему базы данных
    DbHelper instance = DbHelper.getInstance();
    Logger.info(getClass(), "Db helper initialized: "+instance);

    //запуск и привязка созданного сервиса, отвественного за получения обновлений Location'a с App переменной
    Intent intent = new Intent(this, AndroidLocationService.class);

    bindService(intent, new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Logger.info(getClass(), "on service conntected");
            androidLocationService = ((ServiceAwareBinder<AndroidLocationService>)service).getService();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            androidLocationService = null;
        }
    }, Context.BIND_AUTO_CREATE);

    startService(intent);
}

UPD:
In general, so far I have made the following workaround - I made Splash screen activity. An async task is launched in it (in the background), in which the initialization actually takes place. It seems that the User experience has improved, but the problem is that at the start, for some short time, the "gray background" still appears. In onCreate inside the MultiDexApplication subclass, only:
@Override
public void onCreate() {
    super.onCreate();
    App.context = getApplicationContext();
    App.instance = this;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Varakosov, 2015-10-07
@thelongrunsmoke

Opt out of synchronous service. Check fresco initialization speed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question