0

カスタム オブジェクトと文字列を他のアクティビティに送信する必要があります。カスタム オブジェクト (ユーザー) は、Parcelable インターフェイスを実装します。私はこれが好きです:

Intent intent = new Intent("action") ;
Bundle data = new Bundle() ;
data.putString("EDIT", "EDIT");
data.putParcelable("DATA", user ) ; //user is custom object
intent.putExtra("BUNDLE", data) ;
startActivity(intent) ;

他のアクティビティでは、インテントを受け取りますが、EDIT マップ データが null で、Intent の Pacelable データのみで、EDIT 文字列が欠落しています。

Intent intent  = getIntent() ;
String edit = bundle.getString("EDIT") ;  // edit = null should be EDIT
Bundle bundle =intent.getBundleExtra("BUNDLE") ;        

この問題を知っている開発者が他にいますか? 提案をいただけますか? ありがとう。

4

1 に答える 1

1

おい、こう使うんだ

 Intent intent = new Intent(getBaseContext(), NextActivity.class);
 Foo foo = new Foo();
 intent.putExtra("foo ", foo);
 intent.putExtra("string", "hi");
 startActivity(intent);

取得するため

 Foo foo = (Foo) getIntent().getParcelableExtra("foo");
 String mString =  getIntent().getStringExtra("string");
于 2013-04-27T03:26:20.683 に答える