C
C
cepprice2019-11-22 16:31:06
Java
cepprice, 2019-11-22 16:31:06

How is a singleton different from a one-time object definition?

5dd7e14da175f254719465.png
Why is the first block worse than the second? You can also write the first and second block of code once in onCreate() , and then use the database. Or does it mean that when using the second block of code in another Activity , the same instance will be used, and when using the first, a new instance will be created?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-11-22
@cepprice

The answer is written in the question - this is a heavy operation, so they recommend doing it once. A static application instance is not very cool, singletons themselves are generally an anti-pattern, you should not do this.
Better take and learn the basics of Dagger 2, it will immediately become better.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question