1

我有这个父选项卡,我想从中将布尔值发送到我的一个选项卡。我该怎么做?我这个下面会工作,但显然它没有!

这是父选项卡(IncludeTabActivity.java):

Intent i = getIntent();

i.putExtra("FromMyActivity", fromLogin);

        TabActivity ta = (TabActivity) IncludeTabActivity.this;
        ta.getTabHost().setCurrentTab(0);

这是子选项卡:

Bundle extras = getIntent().getExtras();
boolean fromLogin = extras.getBoolean("FromMyActivity");

怎么可能做到这一点?

4

2 回答 2

2

尝试:

SharedPreferences settings = getSharedPreferences("DefaultSettings", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("FromMyActivity", fromLogin);
editor.commit();

然后让它使用

SharedPreferences settings = getSharedPreferences("DefaultSettings", 0);
boolean fromLogin = settings.getBoolean("FromMyActivity", defaultFromLoginValue);
于 2012-07-17T20:04:36.430 回答
0

我接收数据的方式略有不同。

Intent received = getIntent();
boolean dataReceived = received.getExtra("FromMyActivity");
于 2012-07-17T20:04:41.567 回答