旗活动范围热门摧毁目标活动,比创建它 [英] Flag Activity Clear Top destroys target activity and than creating it
问题描述
我看Intent.FLAG_ACTIVITY_CLEAR_TOP的行为。
I am watching a behavior of Intent.FLAG_ACTIVITY_CLEAR_TOP.
例如我有三个活动 A,B和C 现在流量为A - > B - > C
For example i have three activities A,B and C Now Flow is A -> B -> C
现在,当我开始从C使用此标志与下面code。
Now when i am starting A from C with this flag with following code.
Intent intent_to_a=new Intent(C.this,A.class);
intent_to_home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent_to_a);
AFAIK,Intent.FLAG_ACTIVITY_CLEAR_TOP应该删除B和应该恢复一个。它也做相同的,但在一个陌生的方式。 它消除了B,比删除比创建A. A的方法的onDestroy也被调用。 谁能告诉我它是正确的还是不? 如果我不希望它得到破坏我应该怎么办?
AFAIK, Intent.FLAG_ACTIVITY_CLEAR_TOP should remove B and should resume the A .It also does the same but in a strange way. It removes B , than removes A than creates A. Method onDestroy of A is also being called. Can anyone tell me is it proper or not? If i don't want it to get destroy what should i do?
推荐答案
使用FLAG_ACTIVITY_REORDER_TO_FRONT,然后使用一个意图告诉B至完成。
Use FLAG_ACTIVITY_REORDER_TO_FRONT and then use an intent to tell B to finish.
活动B:
private BroadcastReceiver finishReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
finish();
}
};
public void onCreate() {
LocalBroadcastManager.getInstance(this)
.registerReceiver(finishReceiver ,
new IntentFilter("B-finish"));
}
public void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(
finishReceiver );
}
活动C:
LocalBroadcastManager.getInstance(this).sendBroadcast(
new Intent("B-finish"));
Intent intent_to_a=new Intent(C.this,A.class);
intent_to_home.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent_to_a);
这篇关于旗活动范围热门摧毁目标活动,比创建它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!