Android 如何从活动堆栈中删除活动数
我有四个活动(A、B、C、D),序列可以是任何类似的(取决于运行时的需求) 类A的代码如下所示,我们从服务器api响应中获取活动名称,并将其传递给公共类以移动到另一个活动-Android 如何从活动堆栈中删除活动数,android,android-activity,stack,Android,Android Activity,Stack,我有四个活动(A、B、C、D),序列可以是任何类似的(取决于运行时的需求) 类A的代码如下所示,我们从服务器api响应中获取活动名称,并将其传递给公共类以移动到另一个活动- class A extends Activity{ // Other Code of Activity int backCount = getbackCountFromResponse(); // by calling any service String name = getActivity
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
}
}
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
}
}
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
}
}
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);
}
}
类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
}
}
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
}
}
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
}
}
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);
}
}
类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
}
}
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
}
}
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
}
}
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);
}
}
移动到任何活动的通用方法“go”的代码-
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
}
}
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
}
}
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
}
}
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);
}
}
我想从当前位置删除服务中计数的活动数。如何删除。如果您想从活动堆栈中清除上一个任务,并想使另一个活动位于堆栈顶部,则应尝试此操作
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);
希望对您有所帮助。方程混乱,无法理解!我已经更新了问题,请再次检查是否正确understandable@SamosysTechnologies看看下面我的答案,希望它能帮助你。