简体   繁体   English

我的Intent的其他一些缺失

[英]Some extras of my Intent are missing

I have two activities and I am trying to pass some data from one activity to another which shows some strange behavior. 我有两个活动,我试图将一些数据从一个活动传递到另一个活动,这表明某些奇怪的行为。 I am getting data of some keys at the other activity but some of them are missing(null). 我在其他活动中正在获取一些键的数据,但是其中一些丢失(空)。

I am getting mStartStopInfo and mVehicleRide whereas the other 2 keys are missing from the bundle. 我正在获取mStartStopInfomVehicleRide而捆绑包中缺少其他2个键。

Here's the code which starts the other activity: 这是开始其他活动的代码:

    Intent intent = new Intent(this, ConfirmationActivity.class);

    String startStopInfo = String.format("%s - %s", mVehicleRide.getStartStopInfo().getDepartureTime(), mVehicleRidesFromStopsResponse.getStartStopName());
    String endStopInfo   = String.format("%s - %s", mVehicleRide.getEndStopInfo().getDepartureTime(), mVehicleRidesFromStopsResponse.getEndStopName());

    Bundle bundle = new Bundle();
    bundle.putString(INTENT_KEY_START_STOP_INFO, startStopInfo);
    bundle.putString(INTENT_KEY_END_STOP_INFO, endStopInfo);
    bundle.putParcelable(INTENT_KEY_ROUTE_STOP_INFO, mVehicleRide);
    bundle.putString(INTENT_KEY_RIDE_DATE, mVehicleRidesFromStopsResponse.getDate());
    intent.putExtras(bundle);
    startActivityForResult(intent, 1);

Following is the code which collects the data in other activity: 以下是收集其他活动中的数据的代码:

@Override
protected void initData(@Nullable Bundle savedInstanceState) {
    if (savedInstanceState == null) {

        Bundle bundle = getIntent().getExtras();
        if(bundle == null){
            finish();
        }

        mStartStopInfo = bundle.getString(INTENT_KEY_START_STOP_INFO);
        mEndStopInfo = bundle.getString(INTENT_KEY_END_STOP_INFO);
        mVehicleRide = bundle.getParcelable(INTENT_KEY_ROUTE_STOP_INFO);
        mDate = bundle.getString(INTENT_KEY_RIDE_DATE);

     }
}

Is there something which is wrong? 有什么问题吗?

EDIT: I am also getting the following exception: 编辑:我也得到以下异常:

W/ArrayMap: New hash 0 is before end of array hash 235905106 at index 2 key 

java.lang.RuntimeException: here
at android.util.ArrayMap.append(ArrayMap.java:547)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3046)
at android.os.BaseBundle.unparcel(BaseBundle.java:257)
at android.os.BaseBundle.getBoolean(BaseBundle.java:825)
at android.content.Intent.getBooleanExtra(Intent.java:6914)
at io.branch.referral.Branch.checkIntentForSessionRestart(Branch.java:2540)
at io.branch.referral.Branch.access$1100(Branch.java:73)
at io.branch.referral.Branch$BranchActivityLifeCycleObserver.onActivityStarted(Branch.java:2460)
at android.app.Application.dispatchActivityStarted(Application.java:236)
at android.app.Activity.onStart(Activity.java:1258)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1412)
at android.app.Activity.performStart(Activity.java:7015)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2909)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Your information is not enough, but my assumption is wrong variable types.(if the other parts are correct) 您的信息还不够,但是我的假设是错误的变量类型。(如果其他部分正确的话)

Check your variable types you put as extras. 检查您放置为额外变量的变量类型。 You are trying to get all your extras via: 您正在尝试通过以下方式获得所有附加服务:

getStringExtra()

In your case; 就你而言 If any of your extra data type is different than String, they will be null. 如果您的任何其他数据类型与String不同,则它们将为null。

For example; 例如; if your variable type is integer you must get this data via: 如果您的变量类型是整数 ,则必须通过以下方式获取此数据:

getIntExtra()

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

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