应用程序/的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
dependencies {
...
implementation 'com.hannesdorfmann.mosby3:mvi:3.1.0'
implementation 'com.hannesdorfmann.mosby3:mvp:3.1.0'
implementation 'com.hannesdorfmann.mosby3:viewstate:3.1.0'
implementation 'com.hannesdorfmann.mosby3:mvp-lce:3.1.0'
}
我的活动:
import com.hannesdorfmann.mosby3.mvp.MvpActivity;
public class OfferDetailsPdfActivity extends MvpActivity<OfferDetailsPdfMvp.View, OfferDetailsPdfPresenterImplMvp> implements OnPageChangeListener, OfferDetailsPdfMvp.View {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
我的活动 OfferDetailsPdfActivity 上的方法onCreate()
是成功通话。
但是我需要将param传递给activity,所以这里是生产代码:
public class OfferDetailsPdfActivity extends MvpActivity<OfferDetailsPdfMvp.View, OfferDetailsPdfPresenterImplMvp> implements OnPageChangeListener, OfferDetailsPdfMvp.View {
private OfferDetailsPdfPresenterImplMvp presenter;
private int offerId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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);
}
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;
}
现在我的活动方法onCreate()
不是调用,但方法createPresenter()
成功调用。文字 “createPresenter:offerId = 0”
从logcat可以看出,方法onCreate()
未被调用。在logcat中没有文字“ onCreate:extras ... ”
为什么?
这里是logcat:
D/com.myproject.android.customer.ui.OfferDetailsPdfActivity( 946): createPresenter: offerId = 0
Process: com.myproject.android.customer.debug, PID: 30127
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myproject.android.customer.debug/com.myproject.android.customer.ui.OfferDetailsPdfActivity}: java.lang.IllegalArgumentException: Null objects cannot be copied from Realm.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: Null objects cannot be copied from Realm.
at io.realm.Realm.checkValidObjectForDetach(Realm.java:1625)
at io.realm.Realm.copyFromRealm(Realm.java:1318)
at io.realm.Realm.copyFromRealm(Realm.java:1292)
at com.myproject.android.customer.service.OfferService.getOffer(OfferService.java:54)
at com.myproject.android.customer.mvp.presenter.OfferDetailsPdfPresenterImplMvp.loadData(OfferDetailsPdfPresenterImplMvp.java:64)
at com.myproject.android.customer.mvp.presenter.OfferDetailsPdfPresenterImplMvp.<init>(OfferDetailsPdfPresenterImplMvp.java:59)
at com.myproject.android.customer.ui.OfferDetailsPdfActivity.createPresenter(OfferDetailsPdfActivity.java:76)
at com.myproject.android.customer.ui.OfferDetailsPdfActivity.createPresenter(OfferDetailsPdfActivity.java:35)
at com.hannesdorfmann.mosby3.mvp.delegate.ActivityMvpDelegateImpl.createViewIdAndCreatePresenter(ActivityMvpDelegateImpl.java:90)
at com.hannesdorfmann.mosby3.mvp.delegate.ActivityMvpDelegateImpl.onCreate(ActivityMvpDelegateImpl.java:142)
at com.hannesdorfmann.mosby3.mvp.MvpActivity.onCreate(MvpActivity.java:42)
at com.myproject.android.customer.ui.OfferDetailsPdfActivity.onCreate(OfferDetailsPdfActivity.java:58)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
答案 0 :(得分:1)
您正在执行父onCreate方法而没有offerId。更改以下两行
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
到此:
Bundle extras = getIntent().getExtras();
if (savedInstanceState == null) {
super.onCreate(extras);
}