android – How could realm activity migration be executed after an activity starts?-ThrowExceptions

Exception or error:

I have the realm init and configuration setup in the Application’s onCreate method:

public class MyApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        initDagger2();
        initRealm();
        setLoggerContext();
        startLifecycleObserver();
        startActivityLifecycleCallback();
        initFirebasePushNotifications();
    }

}

initRealm() setups the Realm configuration, which is correctly configured.

I have my main activity perform some Realm transaction at its onCreate method:

public class MyActivity {

    @Override
    public void onCreate() {
        super.onCreate();
        //do some Realm transaction
    }

}

Lately we are having some exceptions saying that the Realm Migration is needed for some classes. And the log goes back to MyActivity.onCreate()

The exception is not thrown for all the users, so my guess is that this only happens in rare cases.

I wonder if it is possible for the Activity onCreate to be somehow executed before the Application’s onCreate

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *