How can I prevent service restarting in Android? -
I have a service to show notifications at a specific time and to start this service a My service code is: and broadcast receiver code: How to solve this problem? Write service inside broadcast holder When the app is started, the service begins and displays information and shows the service in the app running on the device, but sometimes the ongoing app service restarts and the message is not displayed. .
increases public service notification service {Private Boolean flag = false; Public static notification compartment. Builder Builder; @ Ivoride Public Ibidinder On Bind (Intent of Intent) {Return Null; } @ Override Public Ink on the Internet (Intent Intent, Int Flag, Int StartID) {Timer Timer = New Timer (); Last Reference Reference = getApplicationContext (); TimerkscheduleAtFixedRate (New Taimrtsk) {@Override (went public void) (if (Chektaim ()) {// Intent intent = new Intent (context notification.}}}, 0, (1000 * 60)); return START_NOT_STICKY ;} private boolean Czech-time () {final terms of reference = find Bose Consort (); Calendar = Calendar.getInstance (); Int hour = calendar.get (calendar. HOUR_OF_DAY); Int min = Calendarkget (calendar .MINUTE); if (hours == 16 and minute == 11) {back true;} other {return false;}} private zero-show notifications () {reference reference = getApplicationContex T (); Uri Alarmsound = Ringtonmangerkget Difolturi (Ringtonmanejr. TYPE_NOTIFICATION); Intent intent = new Intent (context, Prsnbiskti. square); pending pending vertical Prtyasthit = Lmbitintentktaktivti (context, 0, intent, 0); MBuilder = Kanpat new notification. builder (reference) SetSmallIcon (R.drawable.ic_launcher) .setContentTitle ( "Feelinger") .setContentText ( "are you feeling today?") Ksetsund (Alarmsund) KsetContentIntent (pending) KsetAutoCancel ( True) .setVibrate (new long [] {300, 200, 200, 200}); Android.app.NotificationManager mNotificationManager = (android.app.NotificationManager) reference .getSystemService (reference.NETIFICATION_SERVICE); MNotificationManager.notify (100, mbuilder.build ()); }
public class Notification Manager expand the broadcast receiver {@ Override public Ricoid On Risev (REFERENCES, intent Intent) {context.startService (new intent (reference, notification service).); }
@Override public int onStartCommand (Intent Intent, int-flags, int startId) {return START_NOT_STICKY; }
Comments
Post a Comment