views:

530

answers:

1

I know this is possible but I'm not really sure where to start. Has anyone been able to achieve this?

Thanks.

+1  A: 

The DataXmlExporter class described in this article will export a SQL lite DB to an XML file.

http://www.screaming-penguin.com/node/7749

The full example is available in this SVN repo. The ManageData class invokes the export.

http://totsp.com/svn/repo/AndroidExamples/trunk/

You will need to create an application class that exposes the DB and referenced as the application name in the AndroidManifest.xml file. Then use that DB as the argument to the DataXmlExporter constructor.

Here's the application class I use. You should already have a class (probably not named DatabaseHelper) that extends SQLiteOpenHelper

package com.billybobbain.android.someapp;
import android.app.Application;
import android.util.Log;

public class MyApplication extends Application {

   public static final String APP_NAME = "SomeApp";  

   private DatabaseHelper dataHelper;   

   @Override
   public void onCreate() {
      super.onCreate();
      Log.d(APP_NAME, "APPLICATION onCreate");
      this.dataHelper = new DatabaseHelper(this);      
   }

   @Override
   public void onTerminate() {
      Log.d(APP_NAME, "APPLICATION onTerminate");      
      super.onTerminate();      
   }

   public DatabaseHelper getDataHelper() {
      return this.dataHelper;
   }

   public void setDataHelper(DatabaseHelper dataHelper) {
      this.dataHelper = dataHelper;
   }
}
Wayne Young
How would one go about calling this class?
LordSnoutimus
Thanks for the added detail Wayne. I do have another question, If I wanted to export the database when a user presses a button, for example, "Send Database", would I map the button to start an intent for the MyApplication class or the XMLExport class?.
LordSnoutimus
Wayne Young
Thanks for your reply Wayne. I guess my question is, How much of the example above would I need to add to my existing code if I just wanted to include the export XML part. To my understanding I would need the above "MyApplication" class, but how would I start this in an intent as it does not extend Activity?. I am a bit confused as to which sections I would need.Thanks.
LordSnoutimus