Android - Implement singleton with RoboGuice

75 Views Asked by At

How can I implement a singleton in Android using RoboGuice? I would like to have a class that has a method "getInstance" that returns an instance of the class.

This is my solution:

import com.google.inject.Inject;
import com.google.inject.Singleton;

@Singleton
public class SingletonObject {
    @Inject
    private static SingletonObject s;

    private SingletonObject(){
        //do something
    }

    public static final SingletonObject getInstance(){
        return s;
    }
}

It could be a good solution?

0

There are 0 best solutions below