1
donuts
5y

I started looking into building my Android app but wanted to see if I could get a refresher on a few things. The starter template for the Nav Layout isn't exactly functional.

So first question is anyone know any resources like an actually functioning demo project.

Also I need DB access but want to open any db file given the *.db path and the DAO should be persistent, share across all fragments/activities. What would be the best design, way of doing that in Android though.

I don't think you can pass the object between activities but what about fragments. I'm thinking the main app opens the DB and then can pass a DAO Interface to all the fragments to use?

Comments
  • 2
    Search for "Android samples". They have a repo with them.

    Search for SqliteOpenHelper or preferably Room examples.

    If you want to pass actual instances between activities, I think you won't escape static fields. In that regard you might as well make singleton Dao.

    You can take advantage of your "Application" class, to initialize shared instances, that require either Context or teardown. People often do that.

    I you want a bit better DI, take a look at Dagger library.

    I suggest you make a single Activity application in combination with Dagger.
  • 0
    @dontknowshit I use Java which is what I usually use for work, never learned kotlin. Is it mostly for mobile dev?
Add Comment