Integrate My Module having Own DB in Another App

Viewed 137

I have a Notes App which contain DB, I need to use this Notes App as lib or module in My two parent apps, how can I use this in my two apps?

AAR:

If I am using .aar means is there possibility to create or store Database in aar module.

Sub Module:

if I go for sub module I need to create table in each projects.

Individual APP:

If I go for individual app,How I share my DB details.

1 Answers

I guess, the best option for you to using Content provider.

However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object. Together, providers and provider clients offer a consistent, standard interface to data that also handles inter-process communication and secure data access.

Typically you work with content providers in one of two scenarios; you may want to implement code to access an existing content provider in another application, or you may want to create a new content provider in your application to share data with other applications.

Source: https://developer.android.com/guide/topics/providers/content-provider-basics

After you created a content provider in your Notes App other apps can access by content resolver. This is totally similar way as you can access bookmarks or contacts on Android.


One more suggestion: don't forget to take care about security as well if you want to share only between your apps.

If you are using a content provider for sharing data between only your own apps, it is preferable to use the android:protectionLevel attribute set to signature protection. Signature permissions do not require user confirmation, so they provide a better user experience and more controlled access to the content provider data when the apps accessing the data are signed with the same key.

Source: https://developer.android.com/training/articles/security-tips#ContentProviders

Related