方法一:
startActivityForResult(new Intent(getApplicationContext(), UserInfoActivity.class), 0);
在销毁B时加一个标记:
setResult(RESULT_OK);
然后在A里面重写onActivityResult();方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0 && resultCode == RESULT_OK) {
finish();
}
}
这样即可实现功能,但是这样感觉太Low了怎么办?用广播!!!
方法二:
在A的onCreate()方法中
<span style="white-space:pre"> </span>IntentFilter filter = new IntentFilter();
filter.addAction("finish");
registerReceiver(broadcastReceiver, filter);
然后写一个广播
public BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
unregisterReceiver(this);
((Activity) context).finish();
}
};
在B finish之前调用这个
sendBroadcast(new Intent().setAction("finish"));