清空行业后退堆栈堆栈、清空、行业

由网友(口头生意)分享简介:我从活动开始A-> B-> C-> D->电子..when我从D->电子应该在栈没有任何活动,但是,用户可以使用后退按钮从D和去C(无刷新活动C,正常人一样回功能)I start from activity A->B->C->D->E ..when i go from D->E there should be no...

我从活动开始A-> B-> C-> D->电子..when我从D->电子应该在栈没有任何活动,但是,用户可以使用后退按钮从D和去C(无刷新活动C,正常人一样回功能)

I start from activity A->B->C->D->E ..when i go from D->E there should be no activity in stack but, the user can use back button from D and go to C (without refreshing Activity C, like normal back function)

推荐答案

您可以添加一个的BroadcastReceiver 在要关闭(A,B,C,D的所有活动):

You could add a BroadcastReceiver in all activities you want to close (A, B, C, D):

public class MyActivity extends Activity {
    private FinishReceiver finishReceiver;
    private static final String ACTION_FINISH = 
           "com.mypackage.MyActivity.ACTION_FINISH";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        finishReceiver= new FinishReceiver();
        registerReceiver(finishReceiver, new IntentFilter(ACTION_FINISH));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        unregisterReceiver(finishReceiver);
    }

    private final class FinishReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(ACTION_FINISH)) 
                finish();
        }
    }
}

......,并通过调用关闭它们...

... and close them by calling ...

sendBroadcast(new Intent(ACTION_FINISH));

...在活动E.检查this很好的例子的了。

阅读全文

相关推荐

最新文章