【问题标题】:How can i remove number of activity from activity stack如何从活动堆栈中删除活动数量
【发布时间】:2018-08-29 01:18:18
【问题描述】:

我有四个活动(A、B、C、D),顺序可以是任何东西(取决于运行时的要求)

A 类的代码是这样的,我们从服务器 api 响应中获取活动名称并将其传递给公共类以移动到另一个活动 -

class A extends Activity{

   // Other Code of Activity 

    int backCount = getbackCountFromResponse();  // by calling any service

    String name = getActivityNameFromResponse(); // by calling any service

    Move m  = new Move(this);
    m.go(name);


    onBackPressed(){

        // What will be the code to move back according to number of back count
    }
}

B 类的代码是这样的,我们从服务器 api 响应中获取活动名称并将其传递给公共类以移动到另一个活动 -

class B extends Activity{

    int backCount = getbackCountFromResponse();  // by calling any service

    String name = getActivityNameFromResponse(); // by calling any service

    Move m  = new Move(this);
    m.go(name);

    onBackPressed(){

    // What will be the code to move back according to number of back count
    }
}

B 类的代码是这样的,我们从服务器 api 响应中获取活动名称并将其传递给公共类以移动到另一个活动 -

 class C extends Activity{

    // Other Code of Activity 


    int backCount = getbackCountFromResponse();  // by calling any service

    String name = getActivityNameFromResponse(); // by calling any service

    Move m  = new Move(this);
    m.go(name);

    onBackPressed(){

    // What will be the code to move back according to number of back count
    }

}

B 类的代码是这样的,我们从服务器 api 响应中获取活动名称并将其传递给公共类以移动到另一个活动 -

 class D extends Activity{

   // Other Code of Activity     

    int backCount = getbackCountFromResponse();  // by calling any service

    String name = getActivityNameFromResponse(); // by calling any service

    Move m  = new Move(this);
    m.go(name);

    onBackPressed(){

    // What will be the code to move back according to number of back count
    }

}

用于移动到任何活动的通用方法“go”的代码 -

 class Move {

     Context con;
     public Move(Context con){
           this.con = con;
      }


     public void go(String activityname)
     {

         Intent i = new Intent(con, activityname.class)
         this.con.startActivity(i);   

     }
}

我想从当前位置删除计数来自服务的活动数量,我该如何删除。

【问题讨论】:

  • 方程式混乱,看不懂!
  • 我已经更新了问题请再次检查是否可以理解
  • @SamosysTechnologies 看看下面我的回答,希望对你有帮助。

标签: android android-activity stack


【解决方案1】:

如果您想从 Activity 堆栈中清除上一个任务,并希望将另一个 Activity 置于堆栈顶部,那么您应该试试这个。

Intent intent = new Intent(this, AnotherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

如果您不想清除之前的任务,而只想将之前的 Activity 放在前面,请像这样添加这两个标志。

Intent intent = new Intent(this, AnotherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    相关资源
    最近更新 更多