该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
回复 初音是谁 :public class MyService extends Service
public void onCreate() {
super.onCreate();
Log.d("Myservice", "onCreate");
manager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//通过 Builder 来创建 Notification 的
Notification.Builder builder=new Notification.Builder(this);
//设置 通知 图标
builder.setSmallIcon(R.mipmap.ic_launcher);
//设置 通知 显示标题
builder.setTicker("Hi");
//设置 通知栏 标题
builder.setContentTitle("步行运功");
//设置 通知内容
builder.setContentText("正在计步...");
//设置 提醒 声音/震动/指示灯
// builder.setDefaults(Notification.DEFAULT_ALL);
//设置 点击后的跳转 通过 pendingIntent 实现
Intent intent=new Intent(this,MenuActivity.class);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0, intent,0);
builder.setContentIntent(pendingIntent);
//创建 通知
//安卓4.1 及其 以上使用 build()方法 ,以下的使用 builder.getNotification();
Notification notification=builder.build();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
startForeground(1, notification);
}
我代码有没有问题。但是我的通知大概显示到15-30分钟,然后就消失了?是系统内存不足杀的吗?之前能保存几个小时。