Android 在安卓系统中进行两项活动

Android 在安卓系统中进行两项活动,android,android-intent,android-activity,Android,Android Intent,Android Activity,在我的应用程序中,假设我有3个活动A、B、C 在应用程序中,从活动A到B,从B到C 现在我想要的是用户是否在活动C 当它点击按钮时,应该转到活动B。我通过调用finish()实现了这一点。但在活动C中,我得到了服务器的响应。现在我想要的是在得到响应之后,必须调用活动A(不在堆栈中存储活动B的历史记录)。如何实现这一点?意向意向=新意向(C.this,A.class); intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACT

在我的应用程序中,假设我有3个活动A、B、C

在应用程序中,从活动A到B,从B到C

现在我想要的是用户是否在活动C

当它点击按钮时,应该转到活动B。我通过调用
finish()
实现了这一点。但在活动C中,我得到了服务器的响应。现在我想要的是在得到响应之后,必须调用活动A(不在堆栈中存储活动B的历史记录)。如何实现这一点?

意向意向=新意向(C.this,A.class); intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_NEW_TASK); 星触觉(意向)

Intent Intent=新的Intent(C.this,A.class); intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_NEW_TASK); 星触觉(意向)

Intent Intent=新的Intent(C.this,A.class); intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_NEW_TASK); 星触觉(意向)

Intent Intent=新的Intent(C.this,A.class); intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_NEW_TASK);
星触觉(意向)

如果您只想销毁特定的活动,如活动B,则可以使用receiver

// declare your receiver in ActivityB

private MyReceiver receiver;

// register your receiver in onCreate() to get broadcast
registerReceiver(receiver, new IntentFilter("DESTROY"));

// customize BroadcastReceiver to your need   
class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("DESTROY")) 
            finish();
    }
}
在ActivityC中,你可以发送一个接收器来销毁ActivityB

sendBrodcast(new Intent("DESTROY");

ActivityB将获得此广播并自行完成。

如果您只想销毁活动B之类的特定活动,可以使用receiver进行销毁

// declare your receiver in ActivityB

private MyReceiver receiver;

// register your receiver in onCreate() to get broadcast
registerReceiver(receiver, new IntentFilter("DESTROY"));

// customize BroadcastReceiver to your need   
class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("DESTROY")) 
            finish();
    }
}
在ActivityC中,你可以发送一个接收器来销毁ActivityB

sendBrodcast(new Intent("DESTROY");

ActivityB将获得此广播并自行完成。

如果您只想销毁活动B之类的特定活动,可以使用receiver进行销毁

// declare your receiver in ActivityB

private MyReceiver receiver;

// register your receiver in onCreate() to get broadcast
registerReceiver(receiver, new IntentFilter("DESTROY"));

// customize BroadcastReceiver to your need   
class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("DESTROY")) 
            finish();
    }
}
在ActivityC中,你可以发送一个接收器来销毁ActivityB

sendBrodcast(new Intent("DESTROY");

ActivityB将获得此广播并自行完成。

如果您只想销毁活动B之类的特定活动,可以使用receiver进行销毁

// declare your receiver in ActivityB

private MyReceiver receiver;

// register your receiver in onCreate() to get broadcast
registerReceiver(receiver, new IntentFilter("DESTROY"));

// customize BroadcastReceiver to your need   
class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("DESTROY")) 
            finish();
    }
}
在ActivityC中,你可以发送一个接收器来销毁ActivityB

sendBrodcast(new Intent("DESTROY");

ActivityB将获得此广播并自行完成。

为什么不从activity C有目的地启动activity A?@fedorSmirnov然后单击back,它将再次调用activity CW为什么不从activity C有目的地启动activity A?@fedorSmirnov然后单击back,它将再次调用activity CW为什么不呢有目的地从活动C启动活动A?@fedorSmirnov然后单击“上一步”将再次调用活动C为什么不从有目的地从活动C启动活动A?@fedorSmirnov然后单击“上一步”将再次调用活动C