Android Intent传递对象和集合
Article article = JsonUtils.getArticle(content);
intent = new Intent(activity, CompositionCorrect.class);
Bundle bundle = new Bundle();
bundle.putSerializable("ARTICLE", article);
intent.putExtras(bundle);
startActivity(intent); 获取传递的对象 private void initIntentData() {
intent = getIntent();
article = (Article) intent.getSerializableExtra("ARTICLE");
tv_content.setText("" + article.getContent());
spannableStringBuilder = new SpannableStringBuilder(tv_content.getText().toString());
}
传递集合 intent = new Intent(CompositionCorrectActivity.this,PiGaiCompletedActivity.class);
Bundle bundle = new Bundle();
for (int i = 0; i < mSpansCommit.size(); i++) {
mSpansCommit.get(i).setColorSpan(null);
}
bundle.putSerializable("MSPANSCOMMIT", (Serializable)mSpansCommit);
bundle.putSerializable("ARTICLE", article);
intent.putExtras(bundle);
startActivity(intent);
获取集合 mSpansCommit = (List<Span>) intent.getSerializableExtra("MSPANSCOMMIT");