“Service MeasurementBrokerService 正在使用中"在我的申请过程中显示 [英] "Service MeasurementBrokerService is in use" is showing in my application process

查看:19
本文介绍了“Service MeasurementBrokerService 正在使用中"在我的申请过程中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,即 GooglePlayServices 应用程序将我的应用程序进程用于他们的服务,并且还显示进程数为 2.
我附上了相同的屏幕截图.我不知道为什么会这样.
与我的应用进程相比,它占用了更多内存.

I have encountered an issue that GooglePlayServices app is using my application process for their service and also showing the processes count as 2.
I have attached the screenshot for the same. I have no idea why it is happening.
It is taking more memory compare to my app process.


有人可以帮我解决这个问题.

Someone please can help me on this.


此处显示两个进程

推荐答案

我找到的解决方案是将 NotificationListenerService 移动到它自己的 process.在另一个设备上使用 Google Play 服务时.

The solution I found is to move the NotificationListenerService to it's own process. While having Google Play Services on another.

背景

首先,分离NotificationListenerService已经是一个不错的决定,因为在用户授予BIND_NOTIFICATION_LISTENER_SERVICE权限后,这个东西一直在运行.

First of all it is already a good decision to separate the NotificationListenerService, because this thing is running constantly after user grants the BIND_NOTIFICATION_LISTENER_SERVICE permission.

基本上除非另有声明,否则您的应用将使用一个进程.这意味着在运行服务"选项卡中,除了存储在 NotificationListenerService 中的所有通知数据外,您还将看到所有尚未被 GC 收集的垃圾.

Basically unless declared otherwise, your app is going to use one process. This means that inside the "Running Services" tab in addition to all notification data stored in the NotificationListenerService you are going to see all your garbage that is yet to be collected by GC.

如何

为了在自己的进程中运行服务,您需要在 Manifest.xml

In order to run a service in it's own process you need to add the android:process attribute in your Manifest.xml

<service android:name="com.mypackage.services.NotificationService"
android:label="@string/app_name"
android:process=":myawesomeprocess"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">

要记住的事情

进程之间无法正常通信!您将无法从驻留在它自己的进程中的服务访问另一个类.唯一的解决方案是使用广播

You can't communicate between processes in a regular way! You won't be able to access another Class from a Service that resides in it's own process. The only solution is to use Broadcasts

//Send
Intent intent = new Intent("com.mypackage.myaction");
context.sendBroadcast(intent);

//Receive
registerReceiver(broadcastReceiver, new IntentFilter("com.mypackage.myaction"));

BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action!=null&&action.equals("com.mypackage.myaction")) {
            //
        }
    }
};

//Don't forget to unregister
unregisterReceiver(broadcastReceiver);

确保您使用 context 而不是 LocalBroadcastManager,因为它不适用于进程.

Make sure you use context and not LocalBroadcastManager, cause it doesn't work with processes.

这篇关于“Service MeasurementBrokerService 正在使用中"在我的申请过程中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆