android - Need to know when my app send a notification -
i have app, have mainactivity(mr.obvious), service , broadcastreceiver. in mainactivity have alarmmanager this:
intent myintent = new intent(mainactivity.this, broadreceiver.class); pendingintent pendingintent = pendingintent.getbroadcast(mainactivity.this, 0, myintent,0); alarmmanager alarmmanager = (alarmmanager)getsystemservice(alarm_service); alarmmanager.setrepeating(alarmmanager.elapsed_realtime_wakeup, calendar.gettimeinmillis(), alarmmanager.interval_half_day, pendingintent);
in broadcastreceiver have this:
public void onreceive(context context, intent intent) { intent service1 = new intent(context, notifyservice.class); context.startservice(service1); }
and in service, have this:
public int onstartcommand(intent intent, int flags, int startid) { notificationmanager notificationmanager = (notificationmanager) this.getapplicationcontext().getsystemservice(context.notification_service); intent intent1 = new intent(this.getapplicationcontext(),mainactivity.class); notification notification = new notificationcompat.builder(this) .setticker(gettext(r.string.notification_ticker)) .setsmallicon(r.drawable.green) .setcontenttitle(frase()) .setcontenttext(gettext(r.string.notification_text)) .setautocancel(true) .build(); intent1.addflags(intent.flag_activity_single_top| intent.flag_activity_clear_top); notificationmanager.notify(0, notification);}
i want app enable button in mainactivity when user receives notification, possible?
- if in background start activity newly
intent in = new intent(this, mainactivity.class); in.putextra("state", "background"); startactivity(in);
get string compare , control button
if in foreground make button object public control it
use global variable identify mainactivity in foreground or not(using activity life cycle)
ondistroy() onstart()
Comments
Post a Comment