I am still very a new comer to Object Oriented programming and am getting issues with the course inheritance and also the scope of variables in one instantiated class to a different.

I am attempting to build an android application that may read multiple XML feeds and save these to the phone's SQLite database. Each feed includes a different title ("news", "audio_mixes" etc.) and I wish to begin using these names in order to save each feed's data into separate database tables - each one of these named following the feed title.

In diagrammatic terms this is exactly what my classes seem like: alt text

The Primary activity shows two buttons as both versions begins a task - each of which are cases of the TitlesBrowser class. Extra supplies are utilized to pass different values of the_url and the_feed_type variables.

@Override
    public void onCreate(final Bundle icicle) {
        super.onCreate(icicle);
        this.setContentView(R.layout.main);

        this.getNewsButton = (Button) findViewById(R.id.get_news_button);
        this.getNewsButton.setOnClickListener(new OnClickListener() {

            public void onClick(final View v) {
                Intent doGetNews = new Intent(Main.this, TitlesBrowser.class);
                doGetNews.putExtra("the_url", Main.this.getString(R.string.titles_url));
                doGetNews.putExtra("the_feed_type", Main.this.getString(R.string.news_type_var));
                startActivity(doGetNews);
            }
        });

        this.getMixtapesButton = (Button) findViewById(R.id.get_mixtapes_button);
        this.getMixtapesButton.setOnClickListener(new OnClickListener() {

            public void onClick(final View v) {
                Intent doGetMixtapes = new Intent(Main.this, TitlesBrowser.class);
                doGetMixtapes.putExtra("the_url", Main.this.getString(R.string.titles_url));
                doGetMixtapes.putExtra("the_feed_type", Main.this.getString(R.string.mixtapes_type_var));
                startActivity(doGetMixtapes);
            }
        });

    }

The TitlesBrowser class, in the onCreate method, will get the Extra supplies and saves these to private local variables.

Intent i = getIntent();
private String theUrl = (String) i.getStringExtra("the_url");
private String theFeedType = (String) i.getStringExtra("the_feed_type");</pre>

These kinds does a couple of things,

1/ it produces a clear case of the DatabaseHelper class, and utilizes a public set method for the reason that class to pass through on the need for the in your area help theFeedType variable. Getting done it queries the database for just about any existing data (the theFeedType may be the title of every table)

db=new DatabaseHelper(this);
db.setTableName(theFeedType);

dbCursor=db.getReadableDatabase().rawQuery("SELECT _ID, id, title FROM "+theFeedType+" ORDER BY id",    null);

2/ it loads new data in the feed URL by instantiating another class HTTPRequestHelper :

HTTPRequestHelper helper = new HTTPRequestHelper(responseHandler);
helper.performPost(theUrl, theFeedType);

The HTTP demands work fine, and based on which of these two buttons is clicked on, each one of the two different activities display the right XML (i.e. retrieve the right data) - well, i realize that theUrl and theFeedType variables are close to each demonstration of the TitlesBrowser class. One calls:

http://baroquedub.co.united kingdom/get-feed.php?feed=news

and also the other one:

http://baroquedub.co.united kingdom/get-feed.php?feed=audio_mixes

The issue is with the DatabaseHelper class:

public class DatabaseHelper extends SQLiteOpenHelper {
  private static final String DATABASE_NAME="baroquedub.db";
  private String table_name;


  public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, 1);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE "+ table_name + "(_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "id INTEGER, " +
                "title TEXT, " +
                "details TEXT, " +
                "picture TEXT, " +
                "viewed BOOLEAN DEFAULT '0' NOT NULL);");
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    android.util.Log.w("Baroquedub", "Upgrading database, which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS mixtapes");
    onCreate(db);
  }

  public void setTableName(String theName){
    this.table_name = theName;
  }
}

I'd expect it to produce a new table every time it's instantiated (whether "news" or "audio_mixes" was passed from the parent TitlesBrowser class.

However it only works once - basically start the applying and then click "news" a table known as news is produced and every time I go back to that activity it effectively retrieves data from that same database.

But when Then i start another activity by clicking alternatively button (i.e access another feed) I recieve an SQL error saying that the database of this title does not exist. Quite simply the onCreate db.execSQL("CREATE TABLE... method does not seem to get known as again.

It's as though multiple copies from the DatabaseHelper class aren't being produced, although you will find two cases of TitlesBrowser.

-- Here is a illustration showing the issue:

http://screencast.com/t/NDFkZDFmMz

It has been really tricky to describe (specifically for a new!!!) and that i hope it can make some sense. I'd be very grateful for just about any help, advice or guidance.