I have extended the Android.Application class so that I can keep state (using the application as the singleton).
However, I now want to use the Sugar ORM library to simplify my DB access, but the Sugar docs (http://satyan.github.io/sugar/getting-started.html) require that I specify 'SugarApp' as my application class in AndroidManifest.xml.
Which clashes with my Application class that extends Android Application.
Is there an alternative approach?
From the Sugar docs:
E.g. by changing the android:name attribute of the application tag.
<application android:label="@string/app_name" android:icon="@drawable/icon"
android:name="com.orm.SugarApp">
.
.
<meta-data android:name="DATABASE" android:value="sugar_example.db" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example" />
.
.
</application>
Answering my own question -tut tut ;-)
It's simple, I just changed my Custom App class to extend SugarApp instead of Android.Application, as SugarApp itself extends android app!
If you take a look at SugarApp class, you will find that it extends Application class overriding the onCreate() & onTerminate() methods doing its scaffolding:
@Override
public void onCreate() {
super.onCreate();
SugarContext.init(this);
}
@Override
public void onTerminate() {
super.onTerminate();
SugarContext.terminate();
}
The only thing you have to do if you want to keep your base application class is to add those method calls to your custom class.
In this way, you can maintain your custom application class instead of extending SugarApp class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With