カテゴリー
Android Java

ClassをSingletonにするには

public class BackgroundService {
  
  public static BackgroundService getInstance() { return SingletonHolder.INSTANCE; }
  private static class SingletonHolder { private static final BackgroundService INSTANCE = new BackgroundService(); }
  private BackgroundService() {}

}