4

这是我的MVP实现:

public class OfferDetailsPdfActivity extends AppCompatActivity implements OnPageChangeListener, OfferDetailsPdfMvp.View {
  private PdfPresenterImpl presenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
        int offerId = 0;
        if (extras != null) {
            offerId = extras.getInt(Offer.ID);
        }
        presenter = PdfPresenterImpl.getInstance(this, offerId);
}

现在我想使用Moxy

所以这里改变 Activity

public class OfferDetailsPdfActivity extends MvpAppCompatActivity implements OnPageChangeListener, OfferDetailsPdfMvp.View {
    @InjectPresenter
    PdfPresenterImpl presenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
        int offerId = 0;
        if (extras != null) {
            offerId = extras.getInt(Offer.ID);
    }
        // how pass parameter to presenter?
       // presenter = PdfPresenterImpl.getInstance(this, offerId);
}

但是现在我如何将参数传递(context, offerId)给 Presenter?

4

2 回答 2

6

Moxy 有通过自定义构造函数制作 Presenter 的特殊注解@ProvidePreseter。有更多信息示例。另外,我强烈建议不要将上下文传递给演示者。因为那样上下文可能会泄漏。

于 2017-12-25T10:24:11.900 回答
1

@ProvidePresenter应该做的伎俩。查看示例: https ://github.com/Arello-Mobile/Moxy/wiki/Custom-Presenter-constuructor

于 2018-05-11T16:01:27.577 回答