I'm developing an app that use socket to receive messages from a chat.
I'm using an MVP approach and I store the data in a Singleton class named DataBridge
like this:
class myApplication: Application() {
val dataBridge: DataBridge = DataBridge()
val deviceManager: DeviceManager = DeviceManager(this)
override fun onCreate() {
super.onCreate()
instance = this
//init Logger
TimberImplementation.init()
//init Maps
Mapbox.getInstance(this, MAP_ACCESS_TOKEN)
}
companion object {
lateinit var instance: InfiniteApplication
private set
}
}
I have the following scenario:
- Main Activity: create socket connection and update data in
DataBridge
class. It has aViewPagerAdapter
with 4 fragments. Each Fragment has it's ownPresenter
. - Chat Activity: listen changes from
DataBridge
likeonNewMessage
(fired byHomeActivity
) and display the chat
The question is: is a good practice to share Live Model by Application and make it accessible from presenter of different activities?