Closed alexei-28 closed 6 years ago
Hey,
createPresenter()
is called from onCreate(). So you basically have to call super.onCreate() after you have read the bundle like this:
public class OfferDetailsPdfActivity extends MvpActivity<OfferDetailsPdfMvp.View, OfferDetailsPdfPresenterImplMvp> implements OnPageChangeListener, OfferDetailsPdfMvp.View {
private OfferDetailsPdfPresenterImplMvp presenter;
private int offerId;
@Override
protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
Debug.d(TAG, "onCreate: extras = " + AndroidUtil.bundle2String(extras)
+ "\nsavedInstanceState = " + AndroidUtil.bundle2String(savedInstanceState)
);
if (extras != null) {
offerId = extras.getInt(Offer.ID);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.offer_details_pdf);
ButterKnife.bind(this);
}
@NonNull
@Override
public OfferDetailsPdfPresenterImplMvp createPresenter() {
Debug.d(TAG, "createPresenter: offerId = " + offerId);
presenter = new OfferDetailsPdfPresenterImplMvp(this, offerId);
return presenter;
}
Im really sorry about that. It has some historical reasons and I don't want to break backward compatibility. Sorry.
Let me know if that fixes your problem.
Yes, it's help. And now is work.
But... it's not very convenient. I MUST remember that if Activity have incoming params(extras
) I MUST call onCreate()
after read this paramas(extras
). I hope you fix this in the future version.
Thanks.
Most likely it will never be fixed as it would break backward compatibility. Also I don't consider this as a bug.
The problem is the following:
public FooActivity extends MvpActivity<FooView, FooPresenter> {
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle); // if we don't create the presenter in super.onCreate()
presenter.loadFoo(); // you can't use presenter here because presenter is null
}
}
So if we move createPresenter()
to something like onStart()
(which happens after onCreate()
) you can't use the presenter in onCreate()
so your code would look like this:
public FooActivity extends MvpActivity<FooView, FooPresenter> {
private int someId;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle); // doesn't create presenter
if (bundle != null)
someId = bundle.getInt("SomeKey");
}
@Override
protected void onStart() {
super.onStart(); // creates the presenter
presenter.loadFoo(); // now you can use the presenter
}
}
app/build.gradle:
Here my activity:
And method
onCreate()
success call.But I need to pass param to activity, so here production code:
And now in my activity method
onCreate()
is not call, but methodcreatePresenter()
was success called. Has text "createPresenter: offerId = 0"As you can see from logcat the method onCreate() was not called. In logcat no text "onCreate: extras..."
Why?
Here logcat: