android - Intent 不传递我的数据

标签 android

我正在尝试将 2 个参数从一个 Activity 发送到另一个 Activity ,但由于某种原因只传递了一个参数。会是什么?

发送 Activity :

showActivity(OrderActivity.class, new Pair("CUSTOMER_ID", customerId), new Pair("CUSTOMER_TYPE", customerType));

接收 Activity :客户 ID 显示为 0,但已获取类型数据

Bundle extras = getIntent().getExtras();

    long customerId = extras.getLong("CUSTOMER_ID");
    int customerType = extras.getInt("CUSTOMER_TYPE");
    Log.d("===customer ", " id : " + customerId + "  type : " + customerType);

showActivity 看起来像这样

protected void showActivity(Class<? extends BaseKaizenActivity> clazz, Pair<String, Object> ... parameters) {
    Intent intent = new Intent(this, clazz);
    if (parameters != null) {
        for (Pair<String, Object> pair : parameters) {
            if (pair.second instanceof Integer) {
                intent.putExtra(pair.first, (Integer)pair.second);  
            }
            else if (pair.second instanceof Parcelable) {
                intent.putExtra(pair.first, (Parcelable)pair.second);
            }
        }
    }
    startActivity(intent);
}

最佳答案

if (pair.second instanceof Integer) {
                intent.putExtra(pair.first, (Integer)pair.second);  
            }
            else if (pair.second instanceof Parcelable) {
                intent.putExtra(pair.first, (Parcelable)pair.second);
            }

好像忘记写Long的子句了,if和else if都没有,所以没有放到extradata中。

关于android - Intent 不传递我的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12382517/

相关文章:

android - 跑猴 Activity

android - 当我单击硬件后退按钮并且键盘已关闭时,上下文操作栏会隐藏

java - 按 "Ctrl+Shift+o"后 OnClickListener 被删除

android - 无法检索新的 intent extra

java - 如何在以下代码中为回收器适配器设置点击监听器?

android - Rackspace CloudFiles HTTP 临时 URL(非 HTTPS)

Android 数据绑定(bind) XML 错误

android - 有时 gcc 在编译 arm abi 的 C++ 代码时会将第一个参数放入 R1 寄存器?

android - Jetpack 撰写 : ViewTreeLifecycleOwner not found

android - Cordova Android 应用程序在 Gradle 中的版本号变化