简体   繁体   English

不调用方法onCreate()

[英]Method onCreate() is not call

app/build.gradle: 应用程序/的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'

}

Here my activity: 这是我的活动:

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);
    }

    }

And method onCreate() on my activity OfferDetailsPdfActivity was success call. 我的活动OfferDetailsPdfActivity的 onCreate()方法是成功调用。

But I need to pass param to activity, so here production code: 但是我需要将param传递给活动,因此这里是生产代码:

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;
    }

And now in my activity method onCreate() is not call, but method createPresenter() was success called. 现在在我的活动方法中未调用onCreate()方法,但成功调用了方法createPresenter() Has text "createPresenter: offerId = 0" 带有文本“ createPresenter:offerId = 0”

As you can see from logcat the method onCreate() was not called. 从logcat中可以看到,没有调用onCreate()方法。 In logcat no text " onCreate: extras... " 在logcat中没有文本“ onCreate:extras ...

Why? 为什么?

Here logcat: 这里的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) 

You are executing the parent onCreate method without an offerId. 您正在执行不带有offerId的父onCreate方法。 Change the following two lines 更改以下两行

super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();

to this: 对此:

Bundle extras = getIntent().getExtras();
if (savedInstanceState == null) { 
    super.onCreate(extras); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM