我有四个活动(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);
}
}
我想从当前位置删除计数来自服务的活动数量,如何删除。
答案 0 :(得分:0)
如果你想从活动堆栈中清除上一个任务,并希望在堆栈顶部进行另一项活动,那么你应该试试这个。
Intent intent = new Intent(this, AnotherActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
如果您不想清除以前的任务,只想将之前的活动放在前面,那么就像这样添加这两个标志。
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);
希望它会对你有所帮助。