The document provides an overview of the Android infrastructure and key concepts:
(1) It describes the layers of an Android application including the presentation layer, application logic layer, and domain layer.
(2) It explains important Android concepts such as the Android runtime environment, Dalvik virtual machine, application lifecycle and activities, and use of contexts.
(3) It discusses alternatives for common tasks like dependency injection with RoboGuice and Dagger, handling resources and views with ButterKnife and AndroidAnnotations, and accessing data with SQLite and ORMLite.
(4) It also briefly covers testing approaches on the DVM and JVM using AndroidTestCase, Robotium, and Robolectric
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();