Is singleton preferable for Android? Why?

551 views Asked by At

I went some interviews, there are asking the below question. Please help me.

Is singleton preferable for Android? Why?

I googled but I didn't get the correct solution. Please give me correct answer.

3

There are 3 answers

0
schmop On

I don't see anything specific to Android in the singleton pattern. It's valid or not based on the program needs/usage, not the platform.

0
amukhachov On

Please check this Singletons vs. Application Context in Android? question. It contains extended description of pros and cons of singleton in your android app.

0
Pablo Lozano On

I think this is a bad question (not the one I'm answering, but the one from the interview) because there isn't a correct and simple answer. It seems someone thought "Android developers have to be more aware about memory limitations than regular Java ones, so they should create as few instances as possible, so a Singleton pattern may help a lot".

But it's just a design pattern to be used when it fits, not as a rule of thumb. Pros and cons must be viewed for each case.

UPDATE: @Birdy's link explains it better.