How to create service to show message in every 15 minute on Home Screen and Remove it when press it

Home / Uncategorized / How to create service to show message in every 15 minute on Home Screen and Remove it when press it

Question:
I need my App to show message in every 15 minutes , I designed custom Toast then put it inside Service when work outside The App , I need to know how to do this and Remove the message when we press it as pictured https://lh3.googleusercontent.com/jSbvieN8bcm6gzYz2MhvrFVbl6RJ8FClBDN__fmdf7cZjALNpDWCnytbBMQ4GMkMDE8=h310-rw

what type The message this will show on Screen Home Toast or what ? and How delete it when press it , I don’t need Notification I need as pictured


Answer:
There are lot of ways to do it. This is one of more efficient method.

Schedule an alarm for 15 minutes and start a wakeful broadcast receiver
public void setAlarm(Context context, long syncTime) {
alarmMgr = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);

Intent intent = new Intent(context, MyService.class);
alarmIntent = PendingIntent.getService(context, 0, intent, 0);

alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
syncTime, syncTime, alarmIntent);

}

Cancel the alarm when someone clicks:public void cancelAlarm(Context context) {
if (alarmMgr != null) {
alarmMgr.cancel(alarmIntent);
}
}
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *