Skip to content

Instantly share code, notes, and snippets.

@yukpiz
Last active August 29, 2015 14:27
Show Gist options
  • Save yukpiz/cd16257cbbb40dd19b97 to your computer and use it in GitHub Desktop.
Save yukpiz/cd16257cbbb40dd19b97 to your computer and use it in GitHub Desktop.

今さらながらActiveAndroidを使う

jarを取得してビルドパスを通す

$ cp ~/Download/activeandroid-3.1-beta.jar ./libs/

build.gradleに以下を追加する。

+ dependencies {
+     compile fileTree(dir: 'libs', include: '*.jar')
+     compile files('libs/activeandroid-3.1-beta.jar')
+ }

AndroidManifest.xmlを設定する

AndroidManifest.xmlに以下を追加する。

<application
  android:label="@string/app_name"
  android:icon="@drawable/ic_launcher"
+ android:name="com.activeandroid.app.Application">
  
+ <meta-data
+   android:name="AA_DB_NAME"
+   android:value="xxxxxxx.db"/>
+ <meta-data
+   android:name="AA_DB_VERSION"
+   android:value="1"/>

</application>

モデル定義

import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;

@Table(name = "Accounts")
public class Account
    extends Model
{
    @Column(name = "user_name")
    public String user_name;

    @Column(name = "active")
    public boolean active;

    public Account()
    {
        super();
    }

    public Account(
            String user_name,
            boolean active)
    {
        super();
        this.user_name = user_name;
        this.active = active;
    }
}

データ追加

Account account = new Account("yukpiz", true);
account.save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment