on ActivityResult()方法,编写在childActivity中从未调用过
我的TabGrpActivity扩展了ActivityGroup.
public class TabGroupActivity extends ActivityGroup
{私人ArrayListmIdList;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(mIdList==null)
mIdList = new ArrayList<String>();
obj = new ScheduleView();
startChildActivity("Activity1", new Intent(this,Activity1.class));
}
public void startChildActivity(String Id,Intent intent)
{
Window window = getLocalActivityManager().startActivity(Id,
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if(window!=null)
{
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
在我的Activity1(一个子活动)调用另一个活动使用startActivityForresult()..代码如下:
mybund.putString("event", obj_rowitem.getevent());
Intent schedule = new Intent(getApplicationContext(), Activity2.class);
schedule.putExtras(mybund);
startActivityForResult(schedule, req_code);
和我还在Activity1中编写了一个onActivityResult方法,代码如下
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
year = data.getExtras().getInt("year");
month=data.getExtras().getInt("month");
date=data.getExtras().getInt("date");
String getdate=year+"-"+month+"-"+date;
readschedules(getdate);
rowitems=getdata(getdate);
listview.setAdapter(new CustomView(getApplicationContext(), rowitems));
}
有一点是我把Activity2称为一个简单的活动,而不是子活动…
我的问题是……在Activity2中调用setResult()之后,控件将转到....我不了解生命周期ActivityGroup.
你应该使用活动上下文而不是应用程序上下文,这样它就会将结果返回给正确的活动。所以:
Intent schedule = new Intent(this, Activity2.class);
或:
Intent schedule = new Intent(Activity1.this, Activity2.class)
有关更多信息,请阅读有关不同上下文的信息。