How to access already created database on app relaunch?

Hi, i have implemented couchbase lite in my Android application. I am facing an issue on getting the already created database. When application is first time installed i create a database instance and use it for database operations like (saving,fetching documents) etc. But when i close the app and relaunch a new instance of database is created hence saved data is lost.
I tried to check if database exists using Database.exists() method but how can i retrieve the already created database instance?
Following is the class i use for all couchbase lite database operations. In constructor the instance couchDB is initialized. On every app relaunch it initializes and create a new resulting in losing all saved data.

   public class NoSQLDatabaseManager {
    private Context context;
    private Database couchDB;
    File directory;
    private String databaseName;

    public Database getCouchDB() {
        return couchDB;

    public File getDirectory() {
        return directory;

   public NoSQLDatabaseManager(Context context, String databaseName) {
        try {
            this.context = context;
            this.databaseName = databaseName;

            // Set Database configuration
            DatabaseConfiguration config = new DatabaseConfiguration();
                        directory = context.getDir(databaseName, Context.MODE_PRIVATE);
            if (Database.exists(databaseName, directory)) {
               couchDB=  ??    *HOW TO GET THE EXSITING DATABASE*
            } else {
                // Create  Open a couchDB with specified name and configuration
                couchDB = new Database(databaseName, config);
                //create users document
        } catch (CouchbaseLiteException e) {
	//this class has all basic functions like creating deleting document etc
	 public void createDocument(String documentId, String documentType, JSONObject documentObject, NOSQLOperation nosqlOperation) throws JSONException {
        try {
            documentObject.put(NoSQLUtils.DOCUMENT_TYPE, documentType);
            HashMap documentMap = new Gson().fromJson(documentObject.toString(), HashMap.class);
            MutableDocument mutableDocument = new MutableDocument(documentId);
        } catch (Exception e) {
	private void createBasicDocument(){
	//creates general documents

Can someone help me out on this? Any help will be appreciated.

The new Database() call will only create a database instance if one does not exist. It will open the existing one if it exists. So you should not have to do anything special as far as checking if database exists. Refer to Getting started tutorial .

If things are not surviving app restarts, then it would have to do with the location where the file is persisted. Use getFileDir() on context instead of getDir() . See examples in the link above

I am not familiar with getDir() but maybe it does not persist it to store

Also, would encourage you to do not refer to “Couchbase Lite” as “CouchDB” . Despite the similar sounding names, the are unrelated.
While couchbase server is somewhat related from a historical perspective , couchDB is a separate project maintained by Apache