Android中的Notification直接实例化方法deprecated的解决

讲起来还是郭神的《Android第一行代码》里的第九章的一条代码,就是Notification的实例化

Notification notification = new Notification(icon, string, System.currentTimeMillis());

这段代码被Eclipse显示为deprecated,后来了解到用Notification.builder即可解决
Intent intent = new Intent(this, NotificationActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.builder = new Notification.builder(this);
builder.setSmallIcon(R.drawable.ic_lauancher);
builder.setContentTitle("XXX");
builder.setContentIntent(pi);
Notification notification = builder.build();
//之后可以用“Alt+/”来调出可用的方法

你可能感兴趣的:(Android学习笔记)