DAO SQLITE MVP Android

Asked

Viewed 48 times

1

I’m creating a project and I’m using 3 layers.. presentation, logic and data access! In my data class I need to access the DAO(sqlite) however I need the context to use my DAO, but I cannot use the context in that class because the context belongs to the presentation layer! how can I solve this problem?

2 answers

1

You can use the general context of the application getAplicationContext()

See if it works like this.

0

There’s a way to create a context I’ll write an example

public class DAO extends SQLiteOpenHelper {

   public DAO (Context context){
       super(context,DB_NAME,null,VERSAO);
   }
}

If it’s in Dbcontroller

   public class DBController {

        private SQLiteDatabase db;
        private DAO dao;

        public DBController(Context context){
            dao = new DAO(context);
        }
}

That’s how I got a context. Any doubt I’m available.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.