Skip to content

Instantly share code, notes, and snippets.

public class FetchingJsonActivity extends AppCompatActivity {
@Inject
UserService userService;
private UserView someView;
private Subscription subscription;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userService.getUser().enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
User user = response.body();
if (userView != null) {
userView.populate(user);
}
}
@oznus
oznus / FetchingJsonActivity.java
Created September 14, 2016 02:59
Fetching json
public class FetchingJsonActivity extends AppCompatActivity {
@Inject
UserService userService;
UserView someView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public class LazySingleton {
private static class Loader {
static volatile LazySingleton INSTANCE = new LazySingleton();
}
private LazySingleton () {}
public static LazySingleton getInstance() {
return Loader.INSTANCE;
public class LazySingleton {
private LazySingleton() {
}
private static volatile LazySingleton sInstance;
public static LazySingleton INSTANCE() {
if (sInstance == null) {
public class LazySingleton {
private LazySingleton() {
}
private static LazySingleton sInstance;
public static LazySingleton INSTANCE() {
public class LazySingleton {
private LazySingleton() {
}
private static LazySingleton sInstance;
public static LazySingleton INSTANCE() {
synchronized (LazySingleton.class) {
@oznus
oznus / LazySingleton.java
Last active February 15, 2016 00:22
LazySingleton
public class LazySingleton {
private LazySingleton() {
}
private static LazySingleton sInstance;
public static LazySingleton INSTANCE() {
if (sInstance == null) {
//Create all Retrofit stuff..
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://api.myserver.com")
.build();
MyService service = restAdapter.create(MyService.class);
//Fetch the user from the api
User user = service.getUser("432947");
//Save it to realm
public interface MyService {
@GET("/users/{user}")
User getUser(@Path("user") String user);
}