42. Activity
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
43. Context
●
Context of current state of the
application/object
44. Context
●
Context of current state of the
application/object
●
Context is a handle to the system it
provides services like
– resolving resources
– obtaining access to databases and
preferences
72. ORMLite
@DatabaseTable(tableName = "accounts")
public class Account {
@DatabaseField(id = true) private String name;
@DatabaseField(canBeNull = false) private String password;
Account() {
// all persisted classes must define a no-arg constructor with at least package
visibility
}
}
73. ORMLite
// you get the SQLiteOpenHelper from your Android Activity
ConnectionSource connectionSource = new AndroidConnectionSource(sqliteOpenHelper);
// instantiate the DAO to handle Account with String id
Dao<Account,String> accountDao = BaseDaoImpl.createDao(connectionSource, Account.class);
TableUtils.createTable(connectionSource, Account.class);
String name = "Jim Smith";
Account account = new Account(name, "_secret");
accountDao.create(account)
Account account2 = accountDao.queryForId(name);
connectionSource.close();