Originally intended to notification detailed explanation and source interpretation of the discovery of the time do not want to write.
Notification Life Insurance
Forget it. Direct Source code
@Override
public int Onstartcommand (Intent Intent, int flags, int startid) {
if (Build.VERSION.SDK_INT < 18) {
Startforeground (gray_service_id, New Notification ());
} else {
Intent innerintent = new Intent (context, auxiliaryservice.class);
StartService (innerintent);
Notification Notification = new Notification ();
Startforeground (gray_service_id, notification);
}
Return Super.onstartcommand (Intent, flags, Startid);
}
/**
* The auxiliary service is used to turn on a notification . Do not create an inner class or recycle a problem
*/
public class Auxiliaryservice extends Service {
@Nullable
@Override
Public IBinder Onbind (Intent Intent) {
return null;
}
@Override
public void OnCreate () {
Super.oncreate ();
}
@Override
public int Onstartcommand (Intent Intent, int flags, int startid) {
Startnotification ();
Return Super.onstartcommand (Intent, flags, Startid);
}
/** Start Notification */
private void Startnotification () {
Notification Notification = new Notification ();
This.startforeground (mqttservice.gray_service_id, notification);
Stopself (); Key If the Auxiliaryservice does not have a component binding system will be recycled
Stopforeground (TRUE);
}
}
Android process keepalive Notification detailed description