我有一些绑定到某个进程的服务的 Android 应用程序。
我发现adb shell top -n 1
返回:
PID PR CPU% S #THR VSS RSS PCY UID Name
31647 0 1% S 70 1733640K 98960K bg u0_a132 com.my.app.dev
31727 0 1% S 29 1523892K 62924K fg u0_a132 com.my.app.dev:myService
即使我的应用程序保持在后台,为什么还要top
PCY
告诉'fg'
ae 前台?
有人可以传播这个问题吗?
这是我的 Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.app.dev"
android:versionName="4.0.1.6700000"
android:versionCode="5033" >
<uses-sdk android:minSdkVersion="10"
android:targetSdkVersion="16" />
<application android:icon="@drawable/icon"
android:label="@string/config_app_name"
android:theme="@style/Theme.NoActionBarAppCompat"
android:name="com.my.app.Mine" >
<!-- we would prefer the launchMode to be standard, but it causes a lot of problems. -->
<activity android:name="com.my.ui.main.MineApp"
android:label="@string/config_app_name"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:theme="@style/Theme.Translucent.NoActionBarAppCompat" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="mine.action.HomeActivity" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxx" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<uses-library android:name="com.google.android.maps" />
<service android:name="com.my.engine.logic.EngineService"
android:process=":myService">
<intent-filter>
<action android:name="com_my_RemoteService" />
<action android:name="com_my_EngineService" />
</intent-filter>
</service>
<receiver
android:name="com.my.engine.analytics.ReferrerReceiver"
android:exported="true" android:process=":myService">
<intent-filter>
<action
android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.BootBroadcastReceiver"
android:process=":myService">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.util.MineWatcherReceiver"
android:process=":myServiceWatcher">
<intent-filter>
<action
android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action
android:name="android.intent.action.BATTERY_OKAY" />
<action
android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action
android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.logic.InitServiceReceiver"
android:exported="true" android:process=":myService">
<intent-filter>
<action android:name="initServiceCheck"/>
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.logic.UpdateCounterReceiver"
android:exported="true" android:process=":myService">
<intent-filter>
<action android:name="updateCustomCounter"/>
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.logic.PackageChangeReceiver"
android:process=":myService">
<intent-filter>
<action
android:name="android.intent.action.PACKAGE_ADDED"/>
<action
android:name="android.intent.action.PACKAGE_REPLACED"/>
<action
android:name="android.intent.action.PACKAGE_REMOVED"/>
<action
android:name="android.intent.action.PACKAGE_INSTALL"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
<!-- for notification try next action -->
<service android:name="com.my.notifications.actions.TryNextNotificationActionService" />
<receiver android:name="com.my.ui.base.EulaReminderReceiver">
<intent-filter>
<action android:name="eulaReminderAction" />
</intent-filter>
</receiver>
<receiver android:name="com.my.ui.base.MineGuiBroadcastReceiver">
<intent-filter>
<action android:name="finishStoppedActivities" />
</intent-filter>
</receiver>
<service android:name="com.my.infra.motion.ActivityRecognitionService"
android:label="ActivityRecognitionService"
android:exported="true"
android:enabled="true"
android:process=":myService">
</service>
</application>
</manifest>
编辑 1
我什至停止了“设置”中的通知但仍在process=":myService
前台
编辑 2
来源:_
if (p == SP_BACKGROUND)
strcpy(proc->policy, "bg");
else if (p == SP_FOREGROUND)
strcpy(proc->policy, "fg");
else
strcpy(proc->policy, "er");
来自 其他问题的答案:
对于 PCY 来说,大部分是未受过教育的,有点随机的,在黑暗中刺伤——
PCY -- Policy -- 确定应用程序应如何被 Android 的内存管理器处理
FG -- Foreground -- 进程被认为是前台进程,不应被杀死以释放内存
BG -- Background -- 进程被认为是后台进程(不在前台主动运行,可能会被杀死以释放内存)