2017-07-06 5 views
0
私がバンドルエキストラデータで活動を開始するには、次のコードを使用

間でその値を失い、私は、データがテントエキストラで保存している見ることができます。バンドル活動

public static Intent newIntent(Context packageContext, AccountItem account, TransactionItem transaction) { 
    Bundle args = new Bundle(); 
    args.putParcelable("arg_key_account", account); 
    args.putParcelable("arg_key_transaction", transaction); 
    args.putInt("test_key", 18); 

    Intent intent = new Intent(packageContext, TransactionConnectActivity.class); 
    intent.putExtra("arg_key", args); 
    intent.putExtra("test_key", 21); 
    return intent; 
} 

enter image description here

しかし、ときに私

protected void onCreate(@Nullable Bundle savedInstanceState) { 
    ... 
    Intent intent = getIntent(); 
    if (intent != null) { 
     int test = intent.getIntExtra("test_key", -1); 
     Bundle args = intent.getExtras().getBundle("arg_key"); 
    } 
    ... 
} 

enter image description here

0123:意図からバンドルエキストラデータを取得しようと、バンドルには、データを持ちません

カスタムオブジェクトにParcelableが実装され、すべてのメンバーがパーセルに書き込まれています。私はこれらの質問と答えを読んだが、私はどこが間違っているのかまだ分かりません。

+0

私は 'writeValue'を使用してStringメンバーをパースします。これは' writeString'を使用する必要があります。 – li2

+0

あなた自身の質問に答えて、その答えを受け入れてください。これにより未回答の質問のリストから質問が削除されます。または、値がない場合は質問を削除してください。ありがとう。 –

答えて

1

必ずParcelable作品を作るために、それ以外の場合はAndroidが原因となるデータを正しく取得できません、writeToParcelcreateFromParcelに正しい方法を使用する必要がありますcreateFromParcel nullオブジェクトを返します。 t。

ここでは、writeStringを使用する必要があるStringメンバーをパーセルするのにwriteValueを使用します。