gpt4 book ai didi

android - Beacon 后台服务有时会被 Android 杀死

转载 作者:行者123 更新时间:2023-12-02 18:58:00 25 4
gpt4 key购买 nike

我正在使用Android Beacon Library 2.0,我的信标后台服务有一个奇怪的问题。我至少手动启动我的应用程序一次,关闭设备并重新启动。如果我转到正在运行的应用程序/服务列表,我会看到我的应用程序的名称(1 个进程,1 个服务),但几秒钟后它就会从列表中消失,因为已被 Android 杀死。有时2或3分钟后它会再次出现,但几秒钟后它就会消失。这种行为不是“规则”,有时服务运行没有问题并保持 Activity 状态。

这是我的 list :

<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:allowBackup="true"
android:icon="@drawable/my_drawable"
android:label="MyApp"
android:theme="@android:style/Theme.Holo"
android:name="BeaconReferenceApplication">
<activity
android:name="org.altbeacon.beaconreference.MonitoringActivity"
android:theme="@android:style/Theme.Holo"
android:label="MyApp" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.altbeacon.beaconreference.RangingActivity"
android:theme="@android:style/Theme.Holo"
android:label="MyApp" >
<intent-filter>
</intent-filter>
</activity>

对于测试,我使用 Samsung Galaxy tab3 (Android 4.4.2) 和 Samsung Galaxy tab4 (Android 4.4.2)

我尝试检查 logcat 消息,这些行也许可以解释一些事情。

E/BeaconManager( 4802): Cannot contact service to set scan periods

D/BeaconManager( 4802): This consumer is not bound. binding: org.altbeacon.beaconreference.BeaconReferenceApplication@42320918

D/BeaconManager( 4802): consumer count is now:1

V/ApplicationPolicy( 2365): isApplicationStateBlocked userId 0 pkgname org.altbeacon.beaconreference

D/CustomFrequencyManagerService( 2365): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT frequency : 1400000 uid : 1000 pid : 2365 pkgName : ACTIVITY_RESUME_BOOSTER@5

W/ActivityManager( 2365): mDVFSHelper.acquire()

D/PhoneStatusBar( 2551): setTransGradationMode=false, mTransparentMode=false, mSemiTransparentMode=false, mMultiWindowMode=false

W/ResourceType( 2365): No known package when getting value for resource number 0x7f020000

D/StatusBarManagerService( 2365): tr p:2365,o:f

W/WindowManager( 2365): Token{432ad010 ActivityRecord{432ace98 u0 org.altbeacon.beaconreference/.MonitoringActivity t3}} failed creating starting window

W/WindowManager( 2365): android.content.res.Resources$NotFoundException: Resource ID #0x7f020000

W/WindowManager( 2365): at android.content.res.Resources.getValue(Resources.java:2354)

W/WindowManager( 2365): at android.content.res.Resources.getDrawable(Resources.java:1919)

W/WindowManager( 2365): at com.android.internal.widget.ActionBarView.setIcon(ActionBarView.java:1037)

W/WindowManager( 2365): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3478)

W/WindowManager( 2365): at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1886)

W/WindowManager( 2365): at com.android.internal.policy.impl.PhoneWindowManager.addStartingWindow(PhoneWindowManager.java:2639)

W/WindowManager( 2365): at com.android.server.wm.WindowManagerService$H.handleMessage(WindowManagerService.java:9140)

W/WindowManager( 2365): at android.os.Handler.dispatchMessage(Handler.java:102)

W/WindowManager( 2365): at android.os.Looper.loop(Looper.java:146)

W/WindowManager( 2365): at adroid.os.HandlerThread.run(HandlerThread.java:61)

D/PointerIcon( 2365): setMouseIconStyle1 pointerType: 1001iconType:101 flag:0

D/PointerIcon( 2365): setMouseCustomIcon IconType is same.101

I/BeaconService( 4802): beaconService version 2.0-samsung1 is starting up

I/BeaconService( 4802): SDK is 18 or higher. Using native Android APIs for BLE scanning


D/PhoneStatusBar( 2551): setTransGradationMode=false, mTransparentMode=false, mSemiTransparentMode=false, mMultiWindowMode=false

W/ResourceType( 2365): No known package when getting value for resource number 0x7f020000

W/WindowManager( 2365): Token{4335a9f8 ActivityRecord{4335a880 u0 org.altbeacon.beaconreference/.RangingActivity t3}} failed creating starting window

W/WindowManager( 2365): android.content.res.Resources$NotFoundException: Resource ID #0x7f020000

W/WindowManager( 2365): at android.content.res.Resources.getValue(Resources.java:2354)

W/WindowManager( 2365): at android.content.res.Resources.getDrawable(Resources.java:1919)

W/WindowManager( 2365): at com.android.internal.widget.ActionBarView.setIcon(ActionBarView.java:1037)

W/WindowManager( 2365): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3478)

W/WindowManager( 2365): at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1886)

W/WindowManager( 2365): at com.android.internal.policy.impl.PhoneWindowManager.addStartingWindow(PhoneWindowManager.java:2639)

W/WindowManager( 2365): at com.android.server.wm.WindowManagerService$H.handleMessage(WindowManagerService.java:9140)

W/WindowManager( 2365): at android.os.Handler.dispatchMessage(Handler.java:102)

W/WindowManager( 2365): at android.os.Looper.loop(Looper.java:146)

W/WindowManager( 2365): at android.os.HandlerThread.run(HandlerThread.java:61)

D/BtGatt.GattService( 3581): onScanResult() - address=F4:B8:5E:E4:BA:4A, rssi=-53

D/BtGatt.GattService( 3581): Binder is dead - unregistering client (5)!

E/BtGatt.GattService( 3581): Exception: android.os.DeadObjectException

W/InputDispatcher( 2365): channel ~ Consumer closed input channel or an error occurred. events=0x9

I/WindowState( 2365): WIN DEATH: Window{43379c08 u0 org.altbeacon.beaconreference/org.altbeacon.beaconreference.RangingActivity}

E/InputDispatcher( 2365): channel ~ Channel is unrecoverably broken and will be disposed!

W/InputDispatcher( 2365): Attempted to unregister already unregistered input channel

I/WindowState( 2365): WIN DEATH: Window{43366f58 u0 org.altbeacon.beaconreference/org.altbeacon.beaconreference.MonitoringActivity}

我的应用程序可以正确检测范围内的所有信标,但我需要一个工作后台服务才能长时间工作。你能告诉我我做错了什么吗?

编辑
我可以假设,如果我在正在运行的程序列表中看到具有“1 个进程和 1 个服务”的应用程序,则该服务处于 Activity 状态并正在运行,如果我看不到它,则该进程未运行?

最佳答案

根据我的理解,我认为无论我使用信标的概念开发哪个应用程序。

我将运行我的服务,直到我的 Activity 在后台运行。当我的应用程序被用户清除时,我将停止扫描所有信标。我的观点是仅当与其绑定(bind)的 Activity 正在运行时才运行服务,否则就停止服务。这也会影响设备电池。

要将服务绑定(bind)到 Activity ,您可以查看 here .

希望能有所帮助。

关于android - Beacon 后台服务有时会被 Android 杀死,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32452271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com