Purpose of Singleton:
The main purpose of the singleton class is to object creation, limiting the number of objects to only one. Since there is only one singleton instance fields of a singleton will occur only once per class, just like static.
Prons:
1. Singleton prevents other objects from instantiating their own copies of the singleton object, ensuring that all objects access the single instance.
2. Since the class controls the instantiation process, the class has the flexibility to change the instantiation process.
3. The advantage of singleton over global variable is that you are absolutely sure of the number of instances when you use Singleton.
Cons:
1. Their state is automatically shared across the entire app.
2. Bugs can often start occurring when that state changes unexpectedly.
3. The relationships between singleton and the code that depends on them is usually not very well defined.
4. Managing their life-cycle can be tricky.
How to implement Singleton class.
Step 1. Create a class.
Step 2. Create an instance of the class which declare as a static.
Step 3. Make the initializer. final Singleton class
Step 4. final Singleton class in android.
How to used Singleton class in Activity in android.
In this example we have save the login details in sharedpreferences storage.
Activity
}