我正在开发一个 Android 应用程序,其中我使用 GSON、Otto 和 Realm 的网络库 Retroift。所以我在应用程序类(扩展应用程序)中创建实例。它使我的应用程序启动时间非常慢。是否有任何替代解决方案来解决这个问题。
public class MyApp extends Application{
private MyApp appInstance;
private MainThreadBus bus;
private RealmConfiguration myAppRealmConfig;
private GSON gson;
private HttpLoggingInterceptor logging;
@Override
public void onCreate() {
super.onCreate();
//Application instance
appInstance = this;
gson = new GsonBuilder()
.setDateFormat(ApiConstants.API_DATE_FORMAT).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.serializeNulls()
.create();
mAppRealmConfig = RealmConfigurationFactory.createMyAppRealmConfiguration(this, secretKey);
appConfig = new AppConfig(); logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
bus = new MainThreadBus();
}
public Gson getGson() {
return gson;
}
public AppConfig getAppConfig() {
return appConfig;
}
}