Room with Multi user Database in Single android App












0















Can we have a multiple databases in single android App using Room? I want to create a new database for every single user. If user1 logged in I have to create a Database for that user like UserDB1, If any new account added I have to create a another Database for that user like UserDb2. If account switch happened between that accounts I should access the user specific Database.How can i achieve that?










share|improve this question



























    0















    Can we have a multiple databases in single android App using Room? I want to create a new database for every single user. If user1 logged in I have to create a Database for that user like UserDB1, If any new account added I have to create a another Database for that user like UserDb2. If account switch happened between that accounts I should access the user specific Database.How can i achieve that?










    share|improve this question

























      0












      0








      0


      1






      Can we have a multiple databases in single android App using Room? I want to create a new database for every single user. If user1 logged in I have to create a Database for that user like UserDB1, If any new account added I have to create a another Database for that user like UserDb2. If account switch happened between that accounts I should access the user specific Database.How can i achieve that?










      share|improve this question














      Can we have a multiple databases in single android App using Room? I want to create a new database for every single user. If user1 logged in I have to create a Database for that user like UserDB1, If any new account added I have to create a another Database for that user like UserDb2. If account switch happened between that accounts I should access the user specific Database.How can i achieve that?







      android database kotlin android-room accountmanager






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 16:49









      karthikarthi

      405




      405
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Maybe you could but this approach is wrong for several reasons. You dont make separate databases for users you make tables with relations to each other, each row is an entry for a user.

          Some tables have a one-to-many relationship like a table that holds order numbers. One user may have many orders. Or the table may have a one-to-one relationship like a user profile. What it breaks down to is, each user has a unique entry and ID, that ID would relate to other tables with their data. You use the ID for the logged in person to get their data.
          Beyond that, you really shouldnt be storing other peoples data in your app, what is the situation where you feel multiple people will be using the same phone for the app? The ideal situation is to have a cloud based server/database that you get your data from so only the current users data is retrieved.

          The final reason you dont do multiple databases is that if you want to add a new field you would have to update every DB created instead of just one.






          share|improve this answer
























          • Thank you for your comment. But you didn't understand my query. I want to keep multiple logged in user in App like gmail. whenever I switch the account, I want to access the specific user data. I don't think this approach is wrong. Still you are thinking that this approach is wrong please explain me with clear example or any reference.

            – karthi
            Nov 22 '18 at 6:18











          • You really think gmail has a database for every user? Or that they store all the email on your phone? Whether you store the data on a phone or on a server the principal is the same, one database with table entries for all users. In the case of something like gmail the only thing they store On the phone are the email addresses for each person who has logged in.

            – Notsileous
            Nov 27 '18 at 14:39













          • Thats okay but you are miss understood my question.

            – karthi
            Nov 28 '18 at 10:09











          • @karthi , I think you do not understand what is being explained above. The best way to tackle the issue is to define a table which is unique to every user.

            – Show Young Soyinka
            Dec 29 '18 at 13:19














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416907%2froom-with-multi-user-database-in-single-android-app%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Maybe you could but this approach is wrong for several reasons. You dont make separate databases for users you make tables with relations to each other, each row is an entry for a user.

          Some tables have a one-to-many relationship like a table that holds order numbers. One user may have many orders. Or the table may have a one-to-one relationship like a user profile. What it breaks down to is, each user has a unique entry and ID, that ID would relate to other tables with their data. You use the ID for the logged in person to get their data.
          Beyond that, you really shouldnt be storing other peoples data in your app, what is the situation where you feel multiple people will be using the same phone for the app? The ideal situation is to have a cloud based server/database that you get your data from so only the current users data is retrieved.

          The final reason you dont do multiple databases is that if you want to add a new field you would have to update every DB created instead of just one.






          share|improve this answer
























          • Thank you for your comment. But you didn't understand my query. I want to keep multiple logged in user in App like gmail. whenever I switch the account, I want to access the specific user data. I don't think this approach is wrong. Still you are thinking that this approach is wrong please explain me with clear example or any reference.

            – karthi
            Nov 22 '18 at 6:18











          • You really think gmail has a database for every user? Or that they store all the email on your phone? Whether you store the data on a phone or on a server the principal is the same, one database with table entries for all users. In the case of something like gmail the only thing they store On the phone are the email addresses for each person who has logged in.

            – Notsileous
            Nov 27 '18 at 14:39













          • Thats okay but you are miss understood my question.

            – karthi
            Nov 28 '18 at 10:09











          • @karthi , I think you do not understand what is being explained above. The best way to tackle the issue is to define a table which is unique to every user.

            – Show Young Soyinka
            Dec 29 '18 at 13:19


















          2














          Maybe you could but this approach is wrong for several reasons. You dont make separate databases for users you make tables with relations to each other, each row is an entry for a user.

          Some tables have a one-to-many relationship like a table that holds order numbers. One user may have many orders. Or the table may have a one-to-one relationship like a user profile. What it breaks down to is, each user has a unique entry and ID, that ID would relate to other tables with their data. You use the ID for the logged in person to get their data.
          Beyond that, you really shouldnt be storing other peoples data in your app, what is the situation where you feel multiple people will be using the same phone for the app? The ideal situation is to have a cloud based server/database that you get your data from so only the current users data is retrieved.

          The final reason you dont do multiple databases is that if you want to add a new field you would have to update every DB created instead of just one.






          share|improve this answer
























          • Thank you for your comment. But you didn't understand my query. I want to keep multiple logged in user in App like gmail. whenever I switch the account, I want to access the specific user data. I don't think this approach is wrong. Still you are thinking that this approach is wrong please explain me with clear example or any reference.

            – karthi
            Nov 22 '18 at 6:18











          • You really think gmail has a database for every user? Or that they store all the email on your phone? Whether you store the data on a phone or on a server the principal is the same, one database with table entries for all users. In the case of something like gmail the only thing they store On the phone are the email addresses for each person who has logged in.

            – Notsileous
            Nov 27 '18 at 14:39













          • Thats okay but you are miss understood my question.

            – karthi
            Nov 28 '18 at 10:09











          • @karthi , I think you do not understand what is being explained above. The best way to tackle the issue is to define a table which is unique to every user.

            – Show Young Soyinka
            Dec 29 '18 at 13:19
















          2












          2








          2







          Maybe you could but this approach is wrong for several reasons. You dont make separate databases for users you make tables with relations to each other, each row is an entry for a user.

          Some tables have a one-to-many relationship like a table that holds order numbers. One user may have many orders. Or the table may have a one-to-one relationship like a user profile. What it breaks down to is, each user has a unique entry and ID, that ID would relate to other tables with their data. You use the ID for the logged in person to get their data.
          Beyond that, you really shouldnt be storing other peoples data in your app, what is the situation where you feel multiple people will be using the same phone for the app? The ideal situation is to have a cloud based server/database that you get your data from so only the current users data is retrieved.

          The final reason you dont do multiple databases is that if you want to add a new field you would have to update every DB created instead of just one.






          share|improve this answer













          Maybe you could but this approach is wrong for several reasons. You dont make separate databases for users you make tables with relations to each other, each row is an entry for a user.

          Some tables have a one-to-many relationship like a table that holds order numbers. One user may have many orders. Or the table may have a one-to-one relationship like a user profile. What it breaks down to is, each user has a unique entry and ID, that ID would relate to other tables with their data. You use the ID for the logged in person to get their data.
          Beyond that, you really shouldnt be storing other peoples data in your app, what is the situation where you feel multiple people will be using the same phone for the app? The ideal situation is to have a cloud based server/database that you get your data from so only the current users data is retrieved.

          The final reason you dont do multiple databases is that if you want to add a new field you would have to update every DB created instead of just one.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 18:31









          NotsileousNotsileous

          31118




          31118













          • Thank you for your comment. But you didn't understand my query. I want to keep multiple logged in user in App like gmail. whenever I switch the account, I want to access the specific user data. I don't think this approach is wrong. Still you are thinking that this approach is wrong please explain me with clear example or any reference.

            – karthi
            Nov 22 '18 at 6:18











          • You really think gmail has a database for every user? Or that they store all the email on your phone? Whether you store the data on a phone or on a server the principal is the same, one database with table entries for all users. In the case of something like gmail the only thing they store On the phone are the email addresses for each person who has logged in.

            – Notsileous
            Nov 27 '18 at 14:39













          • Thats okay but you are miss understood my question.

            – karthi
            Nov 28 '18 at 10:09











          • @karthi , I think you do not understand what is being explained above. The best way to tackle the issue is to define a table which is unique to every user.

            – Show Young Soyinka
            Dec 29 '18 at 13:19





















          • Thank you for your comment. But you didn't understand my query. I want to keep multiple logged in user in App like gmail. whenever I switch the account, I want to access the specific user data. I don't think this approach is wrong. Still you are thinking that this approach is wrong please explain me with clear example or any reference.

            – karthi
            Nov 22 '18 at 6:18











          • You really think gmail has a database for every user? Or that they store all the email on your phone? Whether you store the data on a phone or on a server the principal is the same, one database with table entries for all users. In the case of something like gmail the only thing they store On the phone are the email addresses for each person who has logged in.

            – Notsileous
            Nov 27 '18 at 14:39













          • Thats okay but you are miss understood my question.

            – karthi
            Nov 28 '18 at 10:09











          • @karthi , I think you do not understand what is being explained above. The best way to tackle the issue is to define a table which is unique to every user.

            – Show Young Soyinka
            Dec 29 '18 at 13:19



















          Thank you for your comment. But you didn't understand my query. I want to keep multiple logged in user in App like gmail. whenever I switch the account, I want to access the specific user data. I don't think this approach is wrong. Still you are thinking that this approach is wrong please explain me with clear example or any reference.

          – karthi
          Nov 22 '18 at 6:18





          Thank you for your comment. But you didn't understand my query. I want to keep multiple logged in user in App like gmail. whenever I switch the account, I want to access the specific user data. I don't think this approach is wrong. Still you are thinking that this approach is wrong please explain me with clear example or any reference.

          – karthi
          Nov 22 '18 at 6:18













          You really think gmail has a database for every user? Or that they store all the email on your phone? Whether you store the data on a phone or on a server the principal is the same, one database with table entries for all users. In the case of something like gmail the only thing they store On the phone are the email addresses for each person who has logged in.

          – Notsileous
          Nov 27 '18 at 14:39







          You really think gmail has a database for every user? Or that they store all the email on your phone? Whether you store the data on a phone or on a server the principal is the same, one database with table entries for all users. In the case of something like gmail the only thing they store On the phone are the email addresses for each person who has logged in.

          – Notsileous
          Nov 27 '18 at 14:39















          Thats okay but you are miss understood my question.

          – karthi
          Nov 28 '18 at 10:09





          Thats okay but you are miss understood my question.

          – karthi
          Nov 28 '18 at 10:09













          @karthi , I think you do not understand what is being explained above. The best way to tackle the issue is to define a table which is unique to every user.

          – Show Young Soyinka
          Dec 29 '18 at 13:19







          @karthi , I think you do not understand what is being explained above. The best way to tackle the issue is to define a table which is unique to every user.

          – Show Young Soyinka
          Dec 29 '18 at 13:19






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416907%2froom-with-multi-user-database-in-single-android-app%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to pass form data using jquery Ajax to insert data in database?

          National Museum of Racing and Hall of Fame

          Guess what letter conforming each word