我正在编写一个使用 SomeActivity 扩展 TabActivity 的选项卡。下面是主流程:主Activity会调用SomeActivity。SomeActivity 会将两个活动(activityone 和activitytwo)放到两个选项卡中。这是我的问题,当 SomeActivity 的子活动完成后,我怎么能将一些额外的意图传递给 mainactivity?
这是SomeActivity的主要代码,它将被MainActivity调用。
public class SomeActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(Activity.RESULT_OK);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabSpec spec;
Intent intent; // Reusable Intent for each tab
//TAB1
intent = new Intent(this,ActivityOne.class);
spec = tabHost.newTabSpec("tab1")
.setIndicator("Tab1", res.getDrawable(android.R.drawable.ic_media_play))
.setContent(intent);//
tabHost.addTab(spec);//
//TAB2
intent = new Intent(this,ActivityTwo.class);
spec = tabHost.newTabSpec("tab2")
.setIndicator("Tab1", res.getDrawable(android.R.drawable.ic_media_play))
.setContent(intent);//
tabHost.addTab(spec);//
tabHost.setCurrentTab(0);
}
这是我想向 MainActivity 发送意图的地方。
public class ActivityOne extends Activity{
private void SendIntent()
{
Intent intent = new Intent();
intent.putExtra("information", "someinformation");
// Set result and finish this Activity
setResult(Activity.RESULT_OK, intent);
finish();
}
}