导航到另一个屏幕时广播接收器问题

Broadcast receiver issue while navigating to another screen

每次通话结束时,我都使用广播接收器打开一个activity A。 activity 在 5 秒后重定向到另一个 activity B。

现在当另一个时间调用结束时尽管调用Activity A Broadcast receiver 直接调用Activity B.

这是我的代码。

    public void onReceive(Context context, Intent intent) {
    try {
        if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
            savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
        } else {
            String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
            String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            int state = 0;
            if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                switch (state) {
                    case TelephonyManager.CALL_STATE_IDLE:

                        intent = new Intent(context, Create_log.class);
                        System.out.println("call state called");
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        //intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                        context.startActivity(intent);
                        break;
                }
            } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                state = TelephonyManager.CALL_STATE_OFFHOOK;
            } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                state = TelephonyManager.CALL_STATE_RINGING;
            }

            onCallStateChanged(context, state, number);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

这需要 create_log.class,在 create_log 中,我在 5 秒后调用了另一个 class。

    new Handler().postDelayed(new Runnable() {
    @Override
        public void run() {
            final Intent mainIntent = new Intent(Create_log.this, Home_nav.class);
            Create_log.this.startActivity(mainIntent);
            Create_log.this.finish();
        }
    }, 5000);

代码直接重定向到 class B 并跳过 class A。

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  

在 onRecvie() 方法的 Intent 中尝试使用这一行