public abstract class BaseActivity<P extends BasePresenter> extends AppCompatActivity {
protected P mPresenter;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutId());
_injectPresenter();
initView();
}
protected abstract void initView() ;
private void _injectPresenter() {
//此处获取到PresenterFactiry生成的对象
if (this.getClass().getGenericSuperclass() instanceof ParameterizedType
&&((ParameterizedType) (this.getClass().getGenericSuperclass())).getActualTypeArguments().length>0){
Class mPresenterClass = (Class) ((ParameterizedType) (this.getClass().getGenericSuperclass())).getActualTypeArguments()[0];
mPresenter = CreatePresenterUtil.getInstance(mPresenterClass);
mPresenter.setView(this);
}
}
protected abstract int getLayoutId();
}
@InstanceFactory
public class TextPresenter extends BasePresenter {
public TextPresenter(){}
public void text(String name){
Log.d(TextPresenter.class.getName(),name);
}
@Override
public void setView(BaseActivity view) {
}
}
最后找到InstanceProcess JavaFile javaFile = JavaFile.builder("填入你自己需要在哪里生成代码的包名",tb.build()).build();