我无法使用捆绑包

时间:2016-05-04 13:28:01

标签: android android-studio

这是错误的日志:

  

I / art:背景粘性并发标记扫描GC释放9226(1168KB)   AllocSpace对象,4个(84KB)LOS对象,0%免费,47MB / 47MB,暂停   1.006ms总计123.548ms

     

W / art:暂停所有线程:5.356ms

     

W / ArrayMap:新的哈希0在索引4处的数组哈希6295518的末尾之前   键                                                                      java.lang.RuntimeException:这里                                                                          在android.util.ArrayMap.append(ArrayMap.java:494)                                                                          在android.os.Parcel.readArrayMapInternal(Parcel.java:2483)                                                                          在android.os.BaseBundle.unparcel(BaseBundle.java:221)                                                                          在android.os.BaseBundle.getString(BaseBundle.java:918)                                                                          在   eorder.nm.com.mealplanz.activity.LoginActivity.getDataFromOtherActivity(LoginActivity.java:180)                                                                          在   eorder.nm.com.mealplanz.activity.LoginActivity.initialize(LoginActivity.java:93)                                                                          在   eorder.nm.com.mealplanz.activity.BaseActivityNew.onCreate(BaseActivityNew.java:70)                                                                          在android.app.Activity.performCreate(Activity.java:5953)                                                                          在   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)                                                                          在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)                                                                          在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)                                                                          在android.app.ActivityThread.access $ 800(ActivityThread.java:148)                                                                          在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1292)                                                                          在android.os.Handler.dispatchMessage(Handler.java:102)                                                                          在android.os.Looper.loop(Looper.java:135)                                                                          在android.app.ActivityThread.main(ActivityThread.java:5312)                                                                          at java.lang.reflect.Method.invoke(Native Method)                                                                          在java.lang.reflect.Method.invoke(Method.java:372)                                                                          在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:901)                                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

这是我填写Bundle

的代码
private void gotoLoginActivity() {

    Intent loginIntent = new Intent(context, LoginActivity.class);

    Bundle bundle = new Bundle();

    bundle.putString(AppConstant.CLASSFROM, AppConstant.LOGINACTIVITY);
    bundle.putParcelableArrayList(AppConstant.CARTLIST, orderCartDomains);
    bundle.putDouble(AppConstant.TOTALPRICE, totalprice);
    bundle.putDouble(AppConstant.TAXPRICE, tax);
    bundle.putDouble(AppConstant.SUBGRANDTOTAL, subtotal);


    loginIntent.putExtras(bundle);

    startActivity(loginIntent);
    finish();
}

这是我尝试从Bundle获取数据的地方:

private void getDataFromOtherActivity() {

    Bundle bundle = getIntent().getExtras();

    classFrom = bundle.getString(AppConstant.CLASSFROM);

    if (classFrom.equalsIgnoreCase(AppConstant.ITEMACTIVITY)) {
        orderCartDomains = bundle.getParcelableArrayList(AppConstant.CARTLIST);
        totalrice = bundle.getDouble(AppConstant.TOTALPRICE);
        subgrandtotal = bundle.getDouble(AppConstant.SUBGRANDTOTAL);
        taxprice = bundle.getDouble(AppConstant.TAXPRICE);

    } else if (classFrom.equalsIgnoreCase(AppConstant.LOGINACTIVITY)) {
        orderCartDomains = bundle.getParcelableArrayList(AppConstant.CARTLIST);
        totalrice = bundle.getDouble(AppConstant.TOTALPRICE);
        subgrandtotal = bundle.getDouble(AppConstant.SUBGRANDTOTAL);
        taxprice = bundle.getDouble(AppConstant.TAXPRICE);

    }
}

1 个答案:

答案 0 :(得分:0)

希望此代码有帮助

Bundle bundle = new Bundle();

bundle.putString("name", "Android");
bundle.putString("iname", "iPhone");
Intent intent = new Intent(this, ActivityB.class);
intent.putExtras(bundle);
startActivity(intent);

// In ActivityB.class
public Bundle getBundle = null;
getBundle = this.getIntent().getExtras();

String name = getBundle.getString("name");
String id = getBundle.getString("iname");