Android是杀死我的前台服务力量阻止我的包后,
我一直在这个奋斗2周了。
I've been struggling with this for 2 weeks now.
我开发控制通话时间的应用程序。
I'm developing an app that controls call duration.
我收到braodcast在那里我开始前台服务挂断电话。
I receive a braodcast where I start a foreground service to hang up the call.
不过五分钟更多的Android生效后停止我的包,那么杀死我的过程,导致服务崩溃 - 我想 - (不知道为什么),没有崩溃的消息或任何类型的错误
but after five minutes or more android force stop my package then kills my process which cause the service to crash -I think - (don't know why) with no crash message or any kind of error.
它只是消失了。
和它时间表重新启动,但它永远不会再次启动该服务。
And it Schedules restart but it never start the service again.
这里是logcat的
12-29 00:28:52.857 619-619/? I/ActivityManager: Force stopping package club.androidy.callcontrolfree appid=10006 user=0
12-29 00:28:52.858 619-619/? I/ActivityManager: Killing proc 433:club.androidy.callcontrolfree/u0a10006: force stop club.androidy.callcontrolfree
12-29 00:28:52.894 619-619/? W/ActivityManager: Scheduling restart of crashed service club.androidy.callcontrolfree/.PhoneCallService in 5000ms
12-29 00:28:52.919 619-619/? I/ActivityManager: Force stopping service ServiceRecord{422b1b18 u0 club.androidy.callcontrolfree/.PhoneCallService}
使用
亚行外壳dumpsys
我这这确保了我的服务是正确的优先前台服务
using adb shell dumpsys
I got this which insures that my service is a foreground service with the right priority
*APP* UID 10088 ProcessRecord{41aefb98 27922:club.androidy.callcontrolfree/u0a10088}
user #0 uid=10088
class=club.androidy.callcontrolfree.AnalyticsApplication
dir=/data/app/club.androidy.callcontrolfree-1.apk publicDir=/data/app/club.androidy.callcontrolfree-1.apk data=/data/data/club.androidy.callcontrolfree
packageList=[club.androidy.callcontrolfree]
compat={240dpi}
thread=android.app.ApplicationThreadProxy@41cef800
pid=27922 starting=false lastPss=0
lastActivityTime=-11s768ms lruWeight=14097791 serviceb=false keeping=true hidden=false empty=true
oom: max=15 hidden=9 client=9 empty=15 curRaw=2 setRaw=2 nonStopping=2 cur=2 set=2
curSchedGroup=-1 setSchedGroup=-1 systemNoUi=false trimMemoryLevel=0
adjSeq=63108 lruSeq=10968
setIsForeground=false foregroundServices=true forcingToForeground=null
lastRequestedGc=-12s74ms lastLowMemory=-12s74ms reportLowMemory=false
Services:
- ServiceRecord{41fb2578 u0 club.androidy.callcontrolfree/.PhoneCallService}
和过程LRU列表(按oom_adj排序):
部分
Proc #24: adj=prcp /FS trm= 0 27922:club.androidy.callcontrolfree/u0a10088 (fg-service)
我不是我的服务绑定到任何活动。
I'm not binding my service to any activities
我开始我的服务是这样的:
I start my service like this:
Intent srvIntent = new Intent(context, PhoneCallService.class);
context.stopService(srvIntent);
PhoneCallService.stopService = false;
context.startService(srvIntent);
这是我的 onStartCommand
:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Context context = getApplicationContext();
String txtNotificationTicker = context.getString(R.string.strNotificationTicker);
String txtNotificationTitle = context.getString(R.string.strNotificationContexTitle);
String txtNotificationText = context.getString(R.string.strNotificationContexText);
String ns = Context.NOTIFICATION_SERVICE;
Intent cancelIntent = new Intent(this, StopServiceReceiver.class);
PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(this, 0, cancelIntent
, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action action =
new NotificationCompat.Action
.Builder(R.drawable.ic_cancel
, context.getString(R.string.stop_service), pendingIntentCancel)
.build();
Intent mIntent = new Intent(this,MainActivity.class);
int HELLO_ID = 1;
PendingIntent pendingIntent = PendingIntent.getActivity(this, HELLO_ID, mIntent , 0);
this.mNotificationManager = (NotificationManager) getSystemService(ns);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
Notification notification = builder
.setContentIntent(pendingIntent)
.setContentTitle(new StringBuilder(String.valueOf(txtNotificationTitle)))
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(getBitmap(context, R.drawable.ic_launcher))
.setContentText(new StringBuilder(String.valueOf(txtNotificationText))
.append(": ").append(PHONE_NUMBER).toString())
.setWhen(System.currentTimeMillis())
.setPriority(NotificationCompat.PRIORITY_MAX)
.addAction(action)
.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(1, notification);
this.pt = new PhoneThread();
this.pt.start();
return Service.START_STICKY;
}
我醒获取锁这样
if (PhoneCallService.sCpuWakeLock == null) {
PhoneCallService.sCpuWakeLock = ((PowerManager)
context.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"CCF");
PhoneCallService.sCpuWakeLock.acquire();
Log.e("androidy","wacklock acquired");
}
我已经尝试过这么多的解决方案和谷歌的问题,但没有为我工作。
I have already tried many solutions from SO and google issues but nothing works for me.
我看到了,并试图所有这些:
I saw and tried all these :
Foreground服务就会被杀死,每次
Android前台服务被在一定条件下杀死
Foreground服务被杀害的通知点击
Foreground服务被杀害的Android
谁保持应用程序的用户只有30%的总安装。
Users who keep the app are only 30% from total installs.
我在做什么错了?
很多搜索我解决了它之后自己
After a lot of search I solved it myself
原来,如图所示下面的图片
it turned out that my app was power-intensive as shown in the picture below
因此,Android的是力,5分钟后停止它时,有屏幕上没有任何活动,以节省电力。
Hence, android was force stopping it after 5 minutes when there is no activity on the screen to save power.
我解决了功耗问题,一切都变得确定。
I solved power consumption issues and everything became OK.