July 2015
Beginner to intermediate
600 pages
18h 59m
English
Now that you have a database, your next step is to change a lot of code inside of CrimeLab, swapping it to use mDatabase for storage instead of mCrimes.
Start out by doing some demolition. Strip out all the code related to mCrimes in CrimeLab.
Listing 14.7 Tearing down some walls (CrimeLab.java)
public class CrimeLab {
private static CrimeLab sCrimeLab;
private List<Crime> mCrimes;
private Context mContext;
private SQLiteDatabase mDatabase;
public static CrimeLab get(Context context) {
...
}
private CrimeLab(Context context) {
mContext = context.getApplicationContext();
mDatabase = new CrimeBaseHelper(mContext)
.getWritableDatabase();
mCrimes = new ArrayList<>();
}
public void addCrime(Crime c) {
mCrimes.add(c); ...Read now
Unlock full access