【发布时间】:2015-04-17 14:14:12
【问题描述】:
我想将通知的构建延迟到例如1分钟,我该怎么做?我尝试插入一个处理程序并对其进行 postDelaying,但出现多个错误。
public void customizedOnClick (View view){
String ticker = textTicker.getText().toString();
String title = textTitle.getText().toString();
String body = textBody.getText().toString();
notification.setSmallIcon(R.mipmap.ic_launcher);
notification.setTicker(ticker);
notification.setWhen(System.currentTimeMillis());
notification.setContentTitle(title);
notification.setContentText(body);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);
//Builds notification and issues it
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(uniqueID, notification.build());
}
【问题讨论】:
-
你遇到了什么错误?
-
这是我尝试使用处理程序的时候,但我从原始代码中删除了它。错误:(59, 33) 错误:处理程序是抽象的;无法实例化错误:(60, 16) 错误: 找不到符号方法 postDelayed(
,int) -
您确定您导入了正确的
Handler。java.util.logging包中有一个抽象处理程序。你想要android.os中的那个 -
你可能有错误的导入
-
这是错误的导入,但现在我不知道将 onClick 放在哪里。请看下面的答案。 @Knossos
标签: android build handler delay android-notifications