This example shows how to use notification in a service, and the related classes are Notifyingcontroller and Notifyingservice.
The basic method of using notification in a service is the same as the previous example. We haven't introduced service usage for the time being. The basic concept of service is basically the same as the service in Windows OS: No UI, run in the background. Notification can be said to be the best way to notify users of the service. There is a special introduction to service usage, which is not explained here.
The Notifyingservice implementation displays a notification every 5 seconds within a minute. The icons are smiley faces, expressionless, crying faces:
for(inti = 0; I < 4; ++i) {shownotification (R.drawable.stat_happy, R.string.status_bar_notifications_h Appy_message); if(Mcondition.block (5 * 1000)) Break; Shownotification (R.drawable.stat_neutral, r.string.status_bar_notifications_ok_message); if(Mcondition.block (5 * 1000)) Break; Shownotification (R.drawable.stat_sad, r.string.status_bar_notifications_sad_message); if(Mcondition.block (5 * 1000)) Break; } //Do with our work ... stop the service!Notifyingservice. This. Stopself ();
"Sail Plan 025" 2015 sail plan Android Apidemo Devil steps for App->notification->notifying Service Controller Using Notification in service