In my app,i use a TabActivity with five tabs,each tab contain a ActvityGroup,each ActivityGroup manage more than one Activity.one of ActivtyGroups have two Activies:A and B, when click a button in A,it jump to B.when return to A,i want to display some changed data in B.what i meet is:
first, if i start B and some widget in B get focus,when click back button,app exit directly.i debug it and find when finish B it finish the app at the same time.second,if i start B and none of any widget get focus,when click back button,onKeyDown() in B does not work.
Here is my activitygroup,i ues viewanimator as container:
public class Group extends ActivityGroup
{
private Stack<String>aString;
private LocalActivityManager manager;
private ViewAnimator animator;
private int ID;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.group_products);
aString = new Stack<String>();
animator = (ViewAnimator) findViewById(R.id.pro_va_animator);
manager = getLocalActivityManager();
Intent intent = new Intent(this,Products_Category.class);
startActivity(intent);
}
@Override
public void startActivity(Intent intent)
{
String id = "id" + ID++;
aString.push(id);
View view = manager.startActivity(id, intent).getDecorView();
animator.addView(view);
animator.setDisplayedChild(aString.size() - 1);
}
@Override
public void startActivityForResult(Intent intent,int requestCode)
{
String id = "id" + ID++;
aString.push(id);
View view = manager.startActivity(id, intent).getDecorView();
animator.addView(view);
animator.setDisplayedChild(aString.size() - 1);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
int size = aString.size();
if (size > 0)
{
String topId = aString.pop();
View view = manager.destroyActivity(topId, true).getDecorView();
animator.removeView(view);
if (size > 1)
{
return true;
}
}
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
A subActivity=(A)(manager.getCurrentActivity());
A.handleActivityResult(requestCode, resultCode, data);
break;
}
}
In class B,i rewrite onKeyDown() to add some changed data in bundle:
@Override
public boolean onKeyDown(int keyCode,KeyEvent event)
{
if(keyCode==KeyEvent.KEYCODE_BACK)
{
Log.e("prodcuts_3","inner");
Bundle bundle=new Bundle();
bundle.putString("name",name);
bundle.putString("price",price);
bundle.putString("quantity",quantity);
this.setResult(RESULT_CANCELED,this.getIntent().putExtras(bundle));
this.finish();
return this.getParent().onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
in class A:
public void handleActivityResult(int requestCode,int resultCode,Intent data)
{
if(resultCode==RESULT_CANCELED)
{
String price=data.getExtras().getString("price");
......
}
}
thank you guys in advances!!
add the following to your class which is called from class which extends TabGroupActivity