android - Can't get extras in my BroadcastReceiver -


i've got problem implementing service class. logs works fine in service (extras put , countdown working , notification shown after time up). can't extras, update views. idea make service running when app killed , update multiple timers in recycler view. here code that. information helpful

the part i'm trying register service

intent startserviceintent = new intent(context, timerservice.class);         startserviceintent.putextra(extras_time, timecountinmilliseconds);         context.startservice(startserviceintent);         log.d("service", "startservice");          broadcastreceiver = new broadcastreceiver() {             @override             public void onreceive(context context, intent intent) {                 long millisuntilfinished = intent.getlongextra(extras_countdown, 0l);                  log.d("service", "smthisreceived");                  task.timeleft = string.valueof(timeleft); // here add left time timer                  textviewtimecv.settext(hmstimeformatter(millisuntilfinished)); // handling status bar values                  progressbarcv.setprogress((int) (millisuntilfinished / 1000));             }         };          context.registerreceiver(broadcastreceiver, new intentfilter("android.intent.category.default"));         log.d("service", "receiverregistered"); 

service

public class timerservice extends service {  private countdowntimer ctd; private intent broadcastintent; private int requestcode; private long timecountinmillis;  @nullable @override public ibinder onbind(intent intent) {     return null; }  @override public int onstartcommand(intent intent, int flags, int startid) {     log.d("in service", "+1");      intent notificationintent = new intent(this, mainactivity.class);     requestcode =  (int)(intent.getlongextra(extras_time, 0l));      timecountinmillis = intent.getlongextra(extras_time, 0l);      broadcastintent = new intent(countdown_broadcast_receiver);      pendingintent pendingintent = pendingintent.getactivity(this, requestcode, notificationintent, 0);      notification.builder notification = new notification.builder(this)             .setcontenttitle(gettextfromresource(this, r.string.app_name))             .setcontenttext(gettextfromresource(this, r.string.your_timer) + " "                     + gettextfromresource(this, r.string.is_currently_running))             .setsmallicon(ic_launcher)             .setcontentintent(pendingintent);      startforeground(requestcode, notification.build());      ctd = new countdowntimer(timecountinmillis , 1000) {         @override         public void ontick(long millisuntilfinished) {             broadcastintent.putextra(extras_countdown, millisuntilfinished);             log.d("extras_are_put", string.valueof(millisuntilfinished));         }          @override         public void onfinish() {             stopforeground(true);          }     }.start();      return start_sticky; }} 

my constants

public static final string countdown_broadcast_receiver = "com.example.hp.intimer.timerservice"; public static final string extras_countdown = "countdown"; public static final string extras_time = "time"; 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -