This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Singleton { | |
private volatile static Singleton instance; | |
private Singeton() {} | |
public static Singleton getInstance() { | |
if (instance == null) { | |
synchronized(Singleton.class) { | |
if (instance == null) { | |
instance == new Singleton(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Singleton { | |
INSTANCE; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Singleton { | |
private Singleton() {} | |
public static Singleton getInstance() { | |
return LazyHolder.INSTANCE; | |
} | |
private static class LazyHolder { | |
private static final Singleton INSTANCE = new Singleton(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LeakActivity extends Activity { | |
private final Handler handler = new Handler() { | |
@Override | |
public void handleMessage(Message msg) { | |
// do work | |
} | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NonLeakActivity extends Activity { | |
private NonLeakHandler handler = new NonLeakHandler(this); | |
private static final class NonLeakHandler extends Handler { | |
private final WeakReference<NonLeakActivity> ref; | |
public NonLeakHandler(NonLeakActivity act) { | |
ref = new WeakReference<>(act); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AutoValue | |
public abstract class Product { | |
@SerializedName("id") | |
public abstract long getId(); | |
@SerializedName("name") | |
public abstract String getName(); | |
@SerializedName("price") | |
public abstract float getPrice(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GsonTypeAdapterFactory | |
public abstract class AutoValueGsonFactory implements TypeAdapterFactory { | |
public static TypeAdapterFactory create() { | |
return new AutoValueGson_AutoValueGsonFactory(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AutoValue | |
public abstract class Product { | |
@SerializedName("id") | |
public abstract long getId(); | |
@SerializedName("name") | |
public abstract String getName(); | |
@SerializedName("price") | |
public abstract float getPrice(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AutoValue | |
abstract class ProductBuilder { | |
@SerializedName("id") | |
abstract long getId(); | |
@SerializedName("name") | |
abstract String getName(); | |
@SerializedName("price") | |
abstract float getPrice(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class SampleModule { | |
private static final int CONNECT_TIMEOUT = 15; | |
private static final int WRITE_TIMEOUT = 15; | |
private static final int READ_TIMEOUT = 15; | |
private static final String baseUrl; // your base url; | |
@Provides | |
@Singleton | |
Cache provideOkHttpCache(Application application) { |