Sorry for this question,but I’m really stack .
How to create class or data class , that will be never destroyed till you call specific method .
What I mean is when user is already registered I do not want reacting data for user . I know that activity or fragment get destroyed by application close . How to create some class or service that will work on background service .
It is possible to create once data on android that will not depend on activity or fragment , and will be destroyed only when user will make logout.
If yes can you provide some examples? Or links where I can read about. Thank you .
>Solution :
If you need a class that doesn’t depend on the lifecycle of individual UI components you should look at services: https://developer.android.com/guide/components/services
I quote:
A Service is an application component that can perform long-running
operations in the background. It does not provide a user interface.
Once started, a service might continue running for some time, even
after the user switches to another application. Additionally, a
component can bind to a service to interact with it and even perform
interprocess communication (IPC). For example, a service can handle
network transactions, play music, perform file I/O, or interact with a
content provider, all from the background.
This is not for jus holding data, this is for coordinating some user functionality (like downloading a file or playing music). If you just need to store data look for the different data storage options available: https://developer.android.com/guide/topics/data