0
我在底部有4個按鈕。假設A,B,C,D。這些按鈕是作爲一個小部件創建的,並且包含在每個佈局中。點擊每個按鈕,我打開一個我在Common類中實現的活動。當我的應用程序啓動時A將處於選定狀態,在A下我開始一些活動A1,A2,A3。當我按下B時,B將處於選定狀態,B1活動將開始。當我啓動B1時,我正在設置CLEAR_TOP標誌,但我在A下開始的活動未清除。當我再次點擊A按鈕時,A1活動將開始,A2和A3(以前啓動)等所有活動將被清除。但B1,B2沒有被清除。爲什麼會發生。給Cleartop後活動堆棧未清除
public class TabBar implements OnClickListener{
private Context fContext;
//private Activity fActivity;
private Button btnHome, btnReward, btnProfile, btnFav;
private Activity activity;
//private Button venues,orders,about;
public TabBar(Activity activity, Context context) {
this.activity = activity;
btnHome = (Button)activity.findViewById(R.id.btn_tab_home);
btnReward = (Button)activity.findViewById(R.id.btn_tab_rew);
btnProfile = (Button)activity.findViewById(R.id.btn_tab_profile);
btnFav = (Button)activity.findViewById(R.id.btn_tab_fav);
btnHome.setOnClickListener(this);
btnReward.setOnClickListener(this);
btnProfile.setOnClickListener(this);
btnFav.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.btn_tab_home:
Intent int1 = new Intent(activity, HomeActivity.class);
int1.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
int1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(int1);
activity.finish();
activity.overridePendingTransition(0, 0);
break;
case R.id.btn_tab_rew:
Intent int2 = new Intent(activity, Rewards.class);
int2.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
int2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(int2);
activity.finish();
break;
case R.id.btn_tab_profile:
Intent int3 = new Intent(activity, ProfileActivity.class);
int3.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
int3.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(int3);
activity.finish();
break;
case R.id.btn_tab_fav:
Intent int4 = new Intent(activity, FavouritesActivity.class);
int4.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
int4.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(int4);
activity.finish();
break;
default:
break;
}
}