4

Here my implementation of 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);
}

Now I want to use Moxy.

So here change on 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);
}

But now how I can pass params (context, offerId) to Presenter?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Alex
  • 705
  • 1
  • 9
  • 18

2 Answers2

6

Moxy has special annotation @ProvidePreseter for make Presenter by custom constructor. There is more info and example. Also, I strongly recommended to not pass context to presenter. Because then context may leak.

senneco
  • 1,786
  • 2
  • 12
  • 15
1

@ProvidePresenter should do the trick. Check out the example: https://github.com/Arello-Mobile/Moxy/wiki/Custom-Presenter-constuructor

zavanton
  • 1,424
  • 2
  • 9
  • 14