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 FetchingJsonActivity extends AppCompatActivity { | |
@Inject | |
UserService userService; | |
private UserView someView; | |
private Subscription subscription; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); |
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
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); | |
} | |
} |
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 FetchingJsonActivity extends AppCompatActivity { | |
@Inject | |
UserService userService; | |
UserView someView; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); |
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 LazySingleton { | |
private static class Loader { | |
static volatile LazySingleton INSTANCE = new LazySingleton(); | |
} | |
private LazySingleton () {} | |
public static LazySingleton getInstance() { | |
return Loader.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 LazySingleton { | |
private LazySingleton() { | |
} | |
private static volatile LazySingleton sInstance; | |
public static LazySingleton INSTANCE() { | |
if (sInstance == null) { |
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 LazySingleton { | |
private LazySingleton() { | |
} | |
private static LazySingleton sInstance; | |
public static LazySingleton 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 LazySingleton { | |
private LazySingleton() { | |
} | |
private static LazySingleton sInstance; | |
public static LazySingleton INSTANCE() { | |
synchronized (LazySingleton.class) { |
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 LazySingleton { | |
private LazySingleton() { | |
} | |
private static LazySingleton sInstance; | |
public static LazySingleton INSTANCE() { | |
if (sInstance == null) { |
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
//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 |
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 interface MyService { | |
@GET("/users/{user}") | |
User getUser(@Path("user") String user); | |
} |