简体   繁体   English

提供Cleartop后活动堆栈未清除

[英]Activity stack is not clearing after giving Cleartop

I am having 4 buttons at the bottom. 我在底部有4个按钮。 Suppose A,B,C,D. 假设A,B,C,D。 These buttons I have created as a widget and including in every layouts. 我已将这些按钮创建为小部件,并包含在每个布局中。 ON each button click I am opening one activity which I have implemented in Common class. 在每个按钮上单击,我打开一个我在Common类中实现的活动。 When my application starts A will be on selected state, under AI am starting some activities A1, A2, A3. 当我的应用程序启动时,A将处于选定状态,在AI下将启动一些活动A1,A2,A3。 When I press B, B will be in selected state and B1 activity will be started. 当我按B时,B将处于选定状态,并且B1活动将开始。 I am setting CLEAR_TOP flag when I start B1, but the activities I started under A is not clearing. 我在启动B1时正在设置CLEAR_TOP标志,但是我在A下启动的活动没有清除。 When I click A button again A1 activity will be started and all the activities like A2 and A3(previously started) will be cleared. 当我再次单击A按钮时,将启动A1活动,并且将清除所有活动,如A2和A3(先前已启动)。 But B1, B2 are not getting cleared. 但是B1,B2尚未清除。 why it is happening. 为什么会这样。

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;
    }
}

Note, Clear top stack, will clear all the activities of top of some activity from activity stack, if it is present in activity stack. 注意,清除顶部堆栈,将从活动堆栈中清除某些活动顶部的所有活动(如果存在于活动堆栈中)。 If it is not present in activity stack, then it will push new activity B1 on activity stack. 如果活动堆栈中不存在该活动,则它将新活动B1推送到活动堆栈中。

In your case, Activity B1 is not present in activity stack, so it wont pop any activity from activity stack and will just push a new activity B1 on activity stack. 在您的情况下,活动B1不存在于活动堆栈中,因此它不会从活动堆栈中弹出任何活动,而只会在活动堆栈上推送新的活动B1。

If you want to Implement TabBar, then you should use TabFragment or TabActivity for the purpose. 如果要实现TabBar,则应为此目的使用TabFragment或TabActivity。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM