【发布时间】:2017-03-16 23:53:06
【问题描述】:
我有三项活动。在Activity 一(导航菜单)上,我有一个简单的ClickListener 来启动Activity 二。
Intent intent3 = new Intent(this, SettingsActivity.class);
intent3.putExtra("from", "BaseActivity");
startActivity(intent3);
finish();
break;
在Actvity 三我有一些我需要在Activity 二上的数据。所以我将数据放在Bundle 中,如下所示:
//send Data to Setting Activity
Intent mIntent = new Intent(StartActivity.this, SettingsActivity.class);
Bundle mBundle = new Bundle();
mBundle.putString("from", "SettingsActivity");
mBundle.putSerializable("spinnerHashTagItems", (Serializable) spinner_HashTagItem);
mBundle.putSerializable("spinnerUserItem", (Serializable) spinner_UserItem);
mBundle.putBoolean("isCheckedHashTag", isCheckedHashTag);
mBundle.putBoolean("isCheckedHashTagUser", isCheckedHashTagUser);
mBundle.putBoolean("isCheckedAllFromUser", isCheckedAllFromUser);
mIntent.putExtras(mBundle);
所以如果我启动Activity 两个,我只能从第一个Activity 获得Intent,而不是从第三个获得:
//get loadet Settings from StartActivity
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
//do nothing
}
Bundle bundle1 = getIntent().getExtras();
spinner_HashTagItems.clear();
spinner_HashTagItems = (List<String>) bundle1.getSerializable("spinner_HashTagItem");
spinner_userItems.clear();
spinner_userItems = (List<String>) bundle1.getSerializable("spinner_userItem");
chbox_hashTag.setChecked(bundle1.getBoolean("chbox_hashTag"));
chbox_hashTagUser.setChecked(bundle1.getBoolean("chbox_hashTagUser"));
chbox_allFromUser.setChecked(bundle1.getBoolean("chbox_allFromUser"));
我使用调试器通过Activity 二并从Activity 一中获取Bundle。如何从Activity 三获得Bundle?
【问题讨论】:
-
你的
startActivity(mIntent);在哪里? -
我不想启动 Activity。我只需要数据。活动一是 StartActivity,它在开始时加载设置并将数据提供给 SettingActvity(活动二)。我不想在应用程序启动时启动设置。
-
您有一些数据要从活动一通过活动二发送到活动三,对吧?
-
你应该调用 startActivity 将数据从 Activit 发送到另一个活动。
-
不,我想将我的数据从活动一发送到活动二,但我从活动三获得数据。
标签: android android-intent bundle