Cover by Marko Gargenta

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Refactoring Status Data

The work we did previously for the UpdaterService is not ideal for supporting our next user of this data: the TimelineActivity. Since TimelineActivity will also need to access the same database and fetch the same data, it would be better if we would share some of the same functionality between the UpdaterService and the TimelineActivity.

In order to do that, we’ll create a new Java class, StatusData, and make it the common container for database-related functionality (see Example 9-3). It will be hiding (encapsulating) SQLite in a higher-level class accessible to other parts of the Yamba application. The rest of our app will then just ask for StatusData and will not be concerned with how that data is generated. This is a better design and later will allow us to improve it even further with Content Providers, as explained in Chapter 12.

Example 9-3. StatusData.java

package com.marakana.yamba4;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class StatusData { // 1 private static final String TAG = StatusData.class.getSimpleName(); static final int VERSION = 1; static final String DATABASE = "timeline.db"; static final String TABLE = "timeline"; public static final String C_ID = "_id"; ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required