我有两个版本的应用程序,一个是付费版,另一个是免费版。这两个版本共享通知服务的相同代码。其中一个版本可以正常工作,而另一个版本似乎可以运行代码并启动显示警报的方法,但是这个警报从未显示给用户,而是在logcat中出现了以下内容:
20:23:51.926 I/art: WaitForGcToComplete blocked for 5.737ms for cause DisableMovingGc
04-20 20:23:54.531 I/art: Thread[5,tid=12452,WaitingInMainSignalCatcherLoop,Thread*=0xb7e9eec0,peer=0x32c0a0a0,"Signal Catcher"]: reacting to signal 3
04-20 20:23:54.755 I/art: Wrote stack traces to '/data/anr/traces.txt'
在应用程序的其他领域存在相当多的差异,但最近增加了mixpanel跟踪,我曾经看到过与垃圾收集问题相关联的情况。这在两个应用程序中都存在,但每个应用程序中的跟踪不同。
我查看了traces.txt文件,但老实说它太大了,我不确定自己在找什么。我发现了像这样的东西,但没有帮助:
"ActivityManager" prio=5 tid=16 TimedWaiting
| group="main" sCount=1 dsCount=0 obj=0x12d4c9e0 self=0xb7e73020
| sysTid=579 nice=-2 cgrp=default sched=0/0 handle=0xb7e73628
| state=S schedstat=( 0 0 0 ) utm=2110 stm=2446 core=1 HZ=100
| stack=0xa396a000-0xa396c000 stackSize=1036KB
| held mutexes=
at java.lang.Object.wait!(Native method)
- waiting on <0x1b396375> (a com.android.server.am.ActivityManagerService$5)
at java.lang.Object.wait(Object.java:422)
at com.android.server.am.ActivityManagerService.dumpStackTraces(ActivityManagerService.java:4800)
- locked <0x1b396375> (a com.android.server.am.ActivityManagerService$5)
at com.android.server.am.ActivityManagerService.dumpStackTraces(ActivityManagerService.java:4777)
at com.android.server.am.ActivityManagerService.appNotResponding(ActivityManagerService.java:5018)
at com.android.server.am.BroadcastQueue$AppNotResponding.run(BroadcastQueue.java:171)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
我该如何调试这个问题?
编辑
由于不知道如何进行调试,我只是随意修改并注释掉以下代码,以使服务能够继续运行,因此肯定是在以下代码中导致了Gc错误,但为什么呢?它与其他正常工作的应用程序完全相同。
void sendNotification(String message) {
Log.e(TAG, "send notification");
/*NotificationCompat.Builder mBuilder =
(NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification_icon)
.setContentTitle(message)
.setContentText("since you last serviced your shocks")
.setColor(0xffCDDC39)
.setAutoCancel(true);
Intent resultIntent = new Intent(this, ActivitiesActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ActivitiesActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build());*/
}