【问题标题】:Need to open Notification.java activity when application close or minimize应用程序关闭或最小化时需要打开 Notification.java 活动
【发布时间】:2020-02-08 08:23:21
【问题描述】:

注意: 下面在 MyFirebaseMessageingService.java 中提到的代码

public class MyFirebaseMessagingService extends FirebaseMessagingService {
.......
 @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
..............
ValidateCall(validateRingerRequestModel, new ApiCallback() {
                @Override
                public void onResponse(boolean success, Object response) {
                    if (response != null) {
                        ValidateRingerResponseModel responseModel = (ValidateRingerResponseModel) response;
                        if (responseModel.status) {

                            Intent intent = new Intent(getApplicationContext(), Notification.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.putExtra("data", model);
                            startActivity(intent);
                        }
                    }
                }
            });
}

“通知”是一个简单的活动,它显示一些带有点击事件操作的按钮。当应用程序在前台运行并且通知进来时,只有活动启动,但是当应用程序关闭或最小化或设备处于睡眠模式(电池保护模式或长时间不使用)时,上面的代码被执行但 Notification.java 活动没有打开。

具有较新 android 版本(如 android 9)的设备会遇到该问题,对于旧版本(如 android 6),它可以正常工作。

上面的代码是否遗漏了一些东西,或者是否有任何其他方式可以在所有 android 版本上运行?

请提出建议。谢谢。

【问题讨论】:

标签: android firebase firebase-cloud-messaging android-notifications


【解决方案1】:

您无法从 API 29 的后台启动活动。根据文档

Android 10(API 级别 29)及更高版本对应用在后台运行时何时可以启动 Activity 施加了限制。这些限制有助于最大限度地减少对用户的干扰,并让用户更好地控制屏幕上显示的内容。

https://developer.android.com/guide/components/activities/background-starts#exceptions

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    相关资源
    最近更新 更多