I'm new to Android and I'm trying to use SQLite with Active Android ORM. I have a simple todo app and I'm following the tutorial to setup active android. However, it doesn't tell you where to actually put your model files.
https://github.com/pardom/ActiveAndroid/wiki/Getting-started
I believe I have my AndroidManifest.xml setup correctly, I don't know where to put the class where you actually setup your models. This snippet was provided in the tutorial but I don't know where it goes
public class MyApplication extends SomeLibraryApplication {
@Override
public void onCreate() {
super.onCreate();
ActiveAndroid.initialize(this);
}
}
Also, do I create a new file in app/java/com.blahblah and declare my tables there?
Any help on how to structure this would be appreicated
It's really simple really. After you've added your application class, make sure to add it to your manifest:
<application ***android:name=".MyApplication"*** android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
As for where you put your models, it doesn't matter really. You can have a following structure:
Just make sure to add any of your model classes to manifest. Here's how my manifest would look for above structure:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.dbtest" > <application android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- Set a name for your database --> <meta-data android:name="AA_DB_NAME" android:value="SomeDatabaseName.db" /> <meta-data android:name="AA_DB_VERSION" android:value="5" /> <!-- All of your models (tables) go here, separated by coma --> <meta-data android:name="AA_MODELS" android:value="com.example.dbtest.models.Item, com.example.dbtest.models.Category" /> </application> </manifest>
I think that's all there is to it.