0

シリアライズ可能で整数または文字列を渡そうとしていますが、子アクティビティではシリアライズ可能のみを取得します

親の活動

Intent intent = new Intent(Class1.this, Class2.class);
Bundle bundle = new Bundle();
bundle.putInt("key", 23);
bundle.putSerializable(serializable, object);
intent.putExtras(bundle);
startActivityForResult(intent, 1);

子供の活動

Intent intent = getIntent();
int intKey;
Bundle bundle = intent.getExtras();
object = (Object) bundle.getSerializable(serializable);
intKey = bundle.getInt("key", 0);

シリアル化可能なオブジェクトを取得しましたが、整数も取得できません

4

1 に答える 1

0

バンドルを介さずに、intをIntentに直接配置してみてください。意味 :

intent.putExtra("key", 23);

そしてそれを手に入れてください:

intent.getIntExtra("key", 23);

動作するはずです

しかし、バンドルを使用したい理由がある場合は、コメントでSajmonが言ったことを試すことができます。bundle.getInt("key")どこかで同じではないことを読んだのですが、理由はわかりません。

于 2012-05-21T21:58:11.713 に答える