Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moxy: How pass params to Presenter?

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?

like image 495
Alex Avatar asked Mar 07 '23 09:03

Alex


1 Answers

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.

like image 176
senneco Avatar answered Mar 24 '23 18:03

senneco