0
回答
Android NotificationCompat 后台线程java.lang.Throwable: stack dump问题

在后台服务中下载完一个文件后想通知一下用户,调用v4库里面的NotificationCompat 这个类创建一个通知,后台日志总是打印下面的信息(通知能够正常提示):

java.lang.Throwable: stack dump
12-25 14:57:13.675: W/System.err(8538): 	at java.lang.Thread.dumpStack(Thread.java:496)
12-25 14:57:13.675: W/System.err(8538): 	at android.app.Notification$Builder.applyStandardTemplate(Notification.java:1504)
12-25 14:57:13.675: W/System.err(8538): 	at android.app.Notification$Builder.makeContentView(Notification.java:1624)
12-25 14:57:13.675: W/System.err(8538): 	at android.app.Notification$Builder.buildUnstyled(Notification.java:1673)
12-25 14:57:13.675: W/System.err(8538): 	at android.app.Notification$Builder.build(Notification.java:1726)
12-25 14:57:13.675: W/System.err(8538): 	at android.support.v4.app.NotificationCompatJellybean.build(NotificationCompatJellybean.java:102)
12-25 14:57:13.675: W/System.err(8538): 	at android.support.v4.app.NotificationCompat$NotificationCompatImplJellybean.build(NotificationCompat.java:148)
12-25 14:57:13.675: W/System.err(8538): 	at android.support.v4.app.NotificationCompat$Builder.build(NotificationCompat.java:595)
12-25 14:57:13.675: W/System.err(8538): 	at com.fyfeng.testaccount.MainActivity$1.run(MainActivity.java:84)
12-25 14:57:13.675: W/System.err(8538): 	at java.lang.Thread.run(Thread.java:856)
12-25 14:57:13.683: W/System.err(8538): java.lang.Throwable: stack dump
12-25 14:57:13.683: W/System.err(8538): 	at java.lang.Thread.dumpStack(Thread.java:496)
12-25 14:57:13.683: W/System.err(8538): 	at android.app.Notification$Builder.makeTickerView(Notification.java:1629)
12-25 14:57:13.683: W/System.err(8538): 	at android.app.Notification$Builder.buildUnstyled(Notification.java:1678)
12-25 14:57:13.683: W/System.err(8538): 	at android.app.Notification$Builder.build(Notification.java:1726)
12-25 14:57:13.683: W/System.err(8538): 	at android.support.v4.app.NotificationCompatJellybean.build(NotificationCompatJellybean.java:102)
12-25 14:57:13.683: W/System.err(8538): 	at android.support.v4.app.NotificationCompat$NotificationCompatImplJellybean.build(NotificationCompat.java:148)
12-25 14:57:13.691: W/System.err(8538): 	at android.support.v4.app.NotificationCompat$Builder.build(NotificationCompat.java:595)
12-25 14:57:13.691: W/System.err(8538): 	at com.fyfeng.testaccount.MainActivity$1.run(MainActivity.java:84)
12-25 14:57:13.691: W/System.err(8538): 	at java.lang.Thread.run(Thread.java:856)
12-25 14:57:13.691: W/System.err(8538): java.lang.Throwable: stack dump
12-25 14:57:13.691: W/System.err(8538): 	at java.lang.Thread.dumpStack(Thread.java:496)
12-25 14:57:13.691: W/System.err(8538): 	at android.app.Notification$Builder.applyStandardTemplate(Notification.java:1504)
12-25 14:57:13.691: W/System.err(8538): 	at android.app.Notification$Builder.makeTickerView(Notification.java:1634)
12-25 14:57:13.691: W/System.err(8538): 	at android.app.Notification$Builder.buildUnstyled(Notification.java:1678)
12-25 14:57:13.691: W/System.err(8538): 	at android.app.Notification$Builder.build(Notification.java:1726)


代码直接在Android官网示例拷贝过来的,小改了一下:


	public void onClickButton(View v) {
		showNotify();
	}

	private void showNotify() {
		NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
		mBuilder.setSmallIcon(R.drawable.ic_launcher);
		mBuilder.setContentTitle("My notification");
		mBuilder.setContentText("Hello World!");
		// Creates an explicit intent for an Activity in your app
		Intent resultIntent = new Intent(this, HelloActivity.class);

		// The stack builder object will contain an artificial back stack for
		// the
		// started Activity.
		// This ensures that navigating backward from the Activity leads out of
		// your application to the Home screen.
		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
		// Adds the back stack for the Intent (but not the Intent itself)
		stackBuilder.addParentStack(HelloActivity.class);
		// Adds the Intent that starts the Activity to the top of the stack
		stackBuilder.addNextIntent(resultIntent);
		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
		mBuilder.setContentIntent(resultPendingIntent);
		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		// mId allows you to update the notification later on.
		mNotificationManager.notify(mId, mBuilder.build());
	}




有遇到类似的情况的没? 这个是怎么回事? 在官网上面也没有找到原因。


举报
YU_Z_W
发帖于5年前 0回/2K+阅
顶部