Android Programming Tutorials

(Romina) #1
The Restaurant Store

far, we barely have our first schema version. So, just put a comment to that


effect in onUpgrade(), perhaps something like this:


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// no-op, since will not be called until 2nd schema
// version exists
}

In a production system, of course, we would want to make a temporary


table, copy our current data to it, fix up the real table's schema, then


migrate the data back.


Step #3: Remove Extraneous Code from LunchList..........................


With our menu and thread samples behind us, we can get rid of our option


menu and simplify the code. Get rid of the following items from your


implementation of LunchList:



  • The isActive and progress data members

  • The call to requestWindowFeature() in onCreate()

  • The implementations of onPause(), onResume(),
    onCreateOptionsMenu(), and onOptionsItemSelected()

  • The startWork() and doSomeLongWork() methods, along with the
    longTask Runnable


Step #4: Get Access to the Helper......................................................


We will be using RestaurantHelper as our bridge to the database. Hence,


LunchList will need a RestaurantHelper, to retrieve existing restaurants and


add new ones.


In order to really use the database, though, we need to open and close


access to it from LunchList.


First, create a RestaurantHelper data member named helper.


95
Free download pdf