英文:
Android application process gets killed automatically after running for some time
问题
我的安卓应用在运行一段时间(1小时)后会自动被杀死,以下是当进程终止时打印到控制台的日志。 进程 <包名>(PID 21659)已终止
,在我的应用被杀死之前,还有其他与我的应用无关的服务被杀死。这是因为可用的CPU资源不足吗?
日志
09-10 17:34:49.959 1601 20644 I ActivityManager 进程 com.qti.csm(pid 20762)已终止
09-10 17:34:49.959 1601 20644 D ActivityManager cleanUpApplicationRecord -- 20762
09-10 17:34:49.960 1601 20644 W ActivityManager 正在安排重新启动崩溃的服务 com.qti.csm/.securityLog.RunTask,时间为 66531 毫秒
09-10 17:34:50.670 1601 13143 I ActivityManager 进程 com.razorlabs.cpumeter(pid 23212)已终止
09-10 17:34:50.670 1601 13143 D ActivityManager cleanUpApplicationRecord -- 23212
09-10 17:34:50.680 1601 13143 W ActivityManager 正在安排重新启动崩溃的服务 com.razorlabs.cpumeter/.services.ServiceWorker,时间为 75810 毫秒
09-10 17:34:50.695 1601 9564 I ActivityManager 进程 com.android.inputmethod.latin(pid 23423)已终止
09-10 17:34:50.695 1601 9564 D ActivityManager cleanUpApplicationRecord -- 23423
09-10 17:34:50.695 1601 9564 W ActivityManager 正在安排重新启动崩溃的服务 com.android.inputmethod.latin/.LatinIME,时间为 85795 毫秒
09-10 17:34:50.774 1601 1601 W InputMethodManagerService 由于远程异常,会话关闭失败
09-10 17:34:50.774 1601 1601 W InputMethodManagerService android.os.DeadObjectException
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.BinderProxy.transactNative(本机方法)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.BinderProxy.transact(Binder.java:615)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.internal.view.IInputMethodSession$Stub$Proxy.finishSession(IInputMethodSession.java:305)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.InputMethodManagerService.finishSessionLocked(InputMethodManagerService.java:1631)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.InputMethodManagerService.clearClientSessionLocked(InputMethodManagerService.java:1622)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.InputMethodManagerService.clearCurMethodLocked(InputMethodManagerService.java:1648)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.InputMethodManagerService.onServiceDisconnected(InputMethodManagerService.java:1667)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.app.LoadedApk$ServiceDispatcher.doDeath(LoadedApk.java:1469)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1483)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.Handler.handleCallback(Handler.java:751)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.Handler.dispatchMessage(Handler.java:95)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.Looper.loop(Looper.java:154)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.SystemServer.run(SystemServer.java:363)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.SystemServer.main(SystemServer.java:230)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at java.lang.reflect.Method.invoke(Native Method)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
ActivityManager 进程 android.ext.services(pid 2274)已终止
ActivityManager 进程 com.qualcomm.qcrilmsgtunnel(pid 2028)已终止
ActivityManager 进程 com.android.smspush(pid 2093)已终止
设备信息:
处理器:Qualcomm 骁龙 625
操作系统:Android N
英文:
My android application gets killed automatically after running for some time (1 hour), this is the log that gets printed to the console when the process dies. Process <package name> (PID 21659) has died
, and there are other services killed before my application gets killed which are not related to my application. Is this because of the not enough CPU resources available?
LOGS
09-10 17:34:49.959 1601 20644 I ActivityManager Process com.qti.csm (pid 20762) has died
09-10 17:34:49.959 1601 20644 D ActivityManager cleanUpApplicationRecord -- 20762
09-10 17:34:49.960 1601 20644 W ActivityManager Scheduling restart of crashed service com.qti.csm/.securityLog.RunTask in 66531ms
09-10 17:34:50.670 1601 13143 I ActivityManager Process com.razorlabs.cpumeter (pid 23212) has died
09-10 17:34:50.670 1601 13143 D ActivityManager cleanUpApplicationRecord -- 23212
09-10 17:34:50.680 1601 13143 W ActivityManager Scheduling restart of crashed service com.razorlabs.cpumeter/.services.ServiceWorker in 75810ms
09-10 17:34:50.695 1601 9564 I ActivityManager Process com.android.inputmethod.latin (pid 23423) has died
09-10 17:34:50.695 1601 9564 D ActivityManager cleanUpApplicationRecord -- 23423
09-10 17:34:50.695 1601 9564 W ActivityManager Scheduling restart of crashed service com.android.inputmethod.latin/.LatinIME in 85795ms
09-10 17:34:50.774 1601 1601 W InputMethodManagerService Session failed to close due to remote exception
09-10 17:34:50.774 1601 1601 W InputMethodManagerService android.os.DeadObjectException
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.BinderProxy.transactNative(Native Method)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.BinderProxy.transact(Binder.java:615)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.internal.view.IInputMethodSession$Stub$Proxy.finishSession(IInputMethodSession.java:305)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.InputMethodManagerService.finishSessionLocked(InputMethodManagerService.java:1631)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.InputMethodManagerService.clearClientSessionLocked(InputMethodManagerService.java:1622)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.InputMethodManagerService.clearCurMethodLocked(InputMethodManagerService.java:1648)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.InputMethodManagerService.onServiceDisconnected(InputMethodManagerService.java:1667)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.app.LoadedApk$ServiceDispatcher.doDeath(LoadedApk.java:1469)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1483)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.Handler.handleCallback(Handler.java:751)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.Handler.dispatchMessage(Handler.java:95)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at android.os.Looper.loop(Looper.java:154)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.SystemServer.run(SystemServer.java:363)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.server.SystemServer.main(SystemServer.java:230)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at java.lang.reflect.Method.invoke(Native Method)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
09-10 17:34:50.774 1601 1601 W InputMethodManagerService at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
ActivityManager Process android.ext.services (pid 2274) has died
ActivityManager Process com.qualcomm.qcrilmsgtunnel (pid 2028) has died
ActivityManager Process com.android.smspush (pid 2093) has died
Device information:
Processor: Qualcomm snapdragon 625
Operating system: Android N
答案1
得分: 0
你是否偶尔使用了PackageManager对象?
我曾经遇到过相同的问题,结果发现使用这个对象时会出现奇怪的bug,如果你使用得太频繁,它可能会“死掉”,并导致你的应用也收到“死对象异常”。
如果没有的话,我建议你尝试注释掉在出现异常之前可能添加的代码行,并试图找出是什么原因引起了这个问题。
另外,如果能够提供给我们代码,那会有帮助。
英文:
Do you by any change use PackageManager object?
I've had the same issue and it turned out there's a weird bug using this object, if you are using it too much it may "die" and cause your app to also receive a "dead object exception".
If not, I'd recommend you try to comment out lines that you might have added prior to this exception and try to figure out what is causing that issue.
Also, if it's possible to provide us with code, that would help
答案2
得分: 0
Dan Baruch,谢谢您的回复。我发现我的JNI代码中存在内存泄漏问题,这就是为什么Android会终止我的服务和应用程序的原因。奇怪的是,这个内存泄漏问题发生得非常缓慢,没有日志表明这是因为内存不足导致的。
英文:
Dan Baruch, thanks for the reply. I found that there is a memory leak in my JNI code, which is why android is killing my services and application. And the weird part is that the memory leak is happening very slowly and there are no logs which say this happens because of out of memory
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论