Android process keepalive Notification detailed description

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.