我正在接受Android研究,我有一些问题。
我有这个intentService:
public class SystemService extends IntentService{
public SystemService() {
super("SystemService");
}
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, startId, startId);
return(START_NOT_STICKY);
}
@Override
public void onCreate(){
super.onCreate();
startForeground();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void startForeground(){
Intent notificationIntent = new Intent(this, DashboardActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification noti = new Notification.Builder(getApplicationContext())
.setContentTitle("Foregroundservice")
.setContentText("foreground is active")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent).build();
startForeground(1337, noti);
}
}
为什么,在onCreate()函数中,如果我把函数startForeground()这样,在super.onCreate()之前初始化foregroundservice,前台通知就会消失但是如果put之后看起来有用吗?