Search code examples
androidfirebasefirebase-realtime-databasemodelfirebaseui

How to access model class of another app in a different app both having a common existing database?


There are two different apps that are connected to the same database. One is sort of an admin app that updates and deletes data in the database and the other is sort for the user app which only receives the data in the app. I have used the model class in the admin app to update and delete the data. I want to show this data in the user's app using firebase recycler but for which I require model class that was used how can I achieve that??

MY MODEL CLASS

package com.parth.iitktimes;

import java.io.Serializable;

public class Creator implements Serializable {
    private String name,design,email,phone,downloadUrl,uniquekey;

    public String getDownloadUrl() {
        return downloadUrl;
    }

    public void setDownloadUrl(String downloadUrl) {
        this.downloadUrl = downloadUrl;
    }

    public String getUniquekey() {
        return uniquekey;
    }

    public void setUniquekey(String uniquekey) {
        this.uniquekey = uniquekey;
    }

    public Creator(String name, String design, String email, String phone, String downloadUrl, String uniquekey) {
        this.name = name;
        this.design = design;
        this.email = email;
        this.phone = phone;
        this.downloadUrl = downloadUrl;
        this.uniquekey = uniquekey;
    }

    //empty constructor
    public Creator() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesign() {
        return design;
    }

    public void setDesign(String design) {
        this.design = design;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}

MY FIREBASE CONSOLE

images of firebase console

Architecture enter image description here


Solution

  • Your question is not clear enough to answer correctly, but i think you are trying to access common classes of your app (like data model) from another.

    You should consider using module for your project, generally speaking the code you write for your one app can't directly or indirectly access your other app's data and class even if both app is build by you.

    (Technically it can access using reflection and other methods but you want to use same codebase)

    There are many benefits of building modular app check out this 2019 IO talk

    okay, so how you can access your common classes in both client and admin app? create a new project (in android studio), create a new library module in same project, again create a new app module in same project.

    what you got is two app and one library in one project, you can use that library as a dependency for both of your apps and write common classes in that library.