MVP架构模式
public interface View {
void showData(String data);
}
public class Presenter {
private View view;
public Presenter(View view) { this.view = view; }
public void loadData() { view.showData("Hello MVP"); }
}
Jetpack组件(ViewModel)
public class MyViewModel extends ViewModel {
private MutableLiveData<String> data = new MutableLiveData<>();
public LiveData<String> getData() { return data; }
}
常用第三方库
- • Glide:图片加载
- • Retrofit:网络请求
- • EventBus:事件总线
- • Dagger:依赖注入
Retrofit接口定义示例
public interface ApiService {
@GET("/users/{id}")
Call<User> getUser(@Path("id") int id);
}