我有这个父标签,我想从中向我的一个标签发送一个布尔值。我该怎么做?我这以下是可行的,但显然它没有!
这是父标签(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");
怎么可以这样做?
答案 0 :(得分: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);
答案 1 :(得分:0)
我收到数据的方式完全不同。
Intent received = getIntent();
boolean dataReceived = received.getExtra("FromMyActivity");