首页 > 解决方案 > 当应用程序终止或在后台时,无法通过 fcm 通知启动活动

问题描述

我需要启动一个设备环活动,我收到了一个 fcm 通知。当应用程序处于前台时,它工作正常。如果应用程序处于后台或终止状态,我正在接收通知,但活动没有开始

operation.setStatus(resources.getString(R.string.operation_value_completed));
        resultBuilder.build(operation);
        Intent intent = new Intent(context, AlertActivity.class);
        intent.putExtra(resources.getString(R.string.intent_extra_type), resources.getString(R.string.intent_extra_ring));
        intent.putExtra(resources.getString(R.string.intent_extra_message_text), resources.getString(R.string.intent_extra_stop_ringing));
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        context.startActivity(intent);
    
        if (Constants.DEBUG_MODE_ENABLED) {
            Log.d(TAG, "Ringing is activated on the device");
        }

标签: androidandroid-intentandroid-activityfirebase-cloud-messagingring

解决方案


推荐阅读