“Service MeasurementBrokerService正在使用中”正在我的申请流程中显示

问题描述 投票:14回答:7

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

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

enter image description here

显示两个进程hereenter image description here

android service google-play-services
7个回答
2
投票

在我将gcm添加到我的应用程序后,我今天遇到了这个,并且无法弄清楚这个MeasurementBrokerService究竟是什么用途。我发现的唯一一件事就是这个评论:

“我也有它,并猜测它与通知监听器有关,因为看起来防止macrodroid的通知访问使它停止。(希望我很清楚,我的英语只剩下学校时间......)”

来自here


2
投票

我们也看到过这项服务。该问题原来是使用Google Analytics和NotificationListenerService。

由于某些原因,这两件事情并不能很好地协同工作,导致MeasurementBrokerService始终在运行,并且占用大量内存。

我们的解决方案是删除Google Analytics以获取其他分析解决方案。


2
投票

那些仍然检查这个帖子以获得答案的人,我找到了一个解决方案并在以下网址发布了答案:

what is Google Play services MeasurementBrokerService and how to stop it?

我检查了某种程度上谷歌AppMeasurement服务仍在我的设备上运行。

我采用了以下方法:

以下命令停止firebase的数据收集。

https://firebase.google.com/support/guides/disable-analytics告诉我们以下方法

<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />

仅此一项仍无法阻止appMeasurement初始化。

已解决的第二步是将以下内容添加到app level gradle文件中:

configurations {
    all*.exclude group: 'com.google.firebase', module: 'firebase-core'
}

这基本上删除了firebase分析使用的所有代码。

如果它仍然不起作用,请确保gradle不包含广泛的播放服务依赖性

例如:编译

'com.google.android.gms:play-services-location:10.0.1'

代替

'com.google.android.gms:play-services:10.0.1'

最糟糕的情况,我没有测试这个,因为上面解决它对我来说是:

https://developers.google.com/analytics/devguides/collection/android/v4/advanced

如果没有开发人员的许可,谷歌应该真的停止放置不需要的东西。希望这有助于某人


2
投票

在gradle文件中排除firebase-core库。我遇到了同样的问题。

configurations {
all*.exclude group: 'com.google.firebase', module: 'firebase-core'

}

有关firebase库的更多详细信息,请访问以下链接

http://blog.safedk.com/technology/mobile-sdks-firebase-or-play-services/


0
投票

这可能与您在应用中的Google Analytics集成有关。从Java代码,项目级别和应用程序级别gradle文件中删除Google Analytics引用。此泄漏仅发生在最新的Google Analytics版本中。您可以集成旧版Google Play服务版本(如7.3.0),但没有此问题可以修复此漏洞。


0
投票

我可以通过将Gradle版本从2.3.2设置为2.0.0来解决问题。因此,我必须将Gradle wraper从3.3设置为2.14.1。

我还从buildToolsVersion '25 .0.2'回到buildToolsVersion '23 .0.1'。

通过像这样编译项目,可能在构建环境中进行了许多更改,因为当我将所有内容更改回原始版本时问题消失了,没有MeasurementBrokerService正在运行。


0
投票

我找到的解决方案是将NotificationListenerService移动到它自己的process。将Google Play服务放在另一个上面。

背景

首先,将NotificationListenerService分开已经是一个很好的决定,因为这个东西在用户授予BIND_NOTIFICATION_LISTENER_SERVICE权限后不断运行。

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

如何

要在自己的进程中运行服务,您需要在android:process中添加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">

要记住的事情

您无法以常规方式在进程之间进行通信!您将无法从驻留在其自身进程中的服务访问另一个类。唯一的解决方案是使用广播

//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,因为它不适用于进程。

© www.soinside.com 2019 - 2024. All rights reserved.