Search code examples
androiddynamicandroid-contentprovidermultiple-databases

Android ContentProvider initialization not at application start


is it possible to initialize the contentprovider in the application?

because i need to create a database for every user/server combination and I'm creating the database with the login information in the oncreate method of the the contentprovider!


Solution

  • Based on what it sounds like you are trying to do, you may consider contextualizing your ContentProvider's database access (this may be another way of describing what @Gary B. was getting at):

    When you initialize the content provider, create a database within which you will store the list of user/server combinations. Then, when a user logs into the application, create the corresponding database and update the master list for the ContentProvider.

    In the ContentProvider's public operations, determine which user/server combination is active (or being requested) and then look up the appropriate database in the master database you created on installation. You can then read the user/server specific information and return this to the caller.

    Alternatively, you could likely implement this all within one database, but I don't understand enough about your requirements to recommend a specific approach...