android - Broadcast Receiver is not receiving the intent after I change the Intent action -


i trying build simple count down timer app. mainactivity starts service(timerservice). service starts countdowntimer. after every tick, send out broadcast update view in mainactivity. view time updates till last tick. when countdowntimer finishes, creating intent action indicate timer has finished. intent not being received broadcastreceiver.

this countdowntimer code.

    @override     public void onfinish() {         log.i(tag, "timer finished");         intent notifymainact = new intent(constants.time_over);         notifymainact.putextra(constants.get_timer_value,string.valueof(0));         sendbroadcast(notifymainact);         stopself(servicestartid);         log.i(tag, "stopping service " +servicestartid);      }      @override     public void ontick(long millisuntilfinished) {         long minremaining = millisuntilfinished/60000;         log.i(tag, "on tick: "+string.valueof(minremaining));         intent notifymainact = new intent(constants.broadcast_action);         notifymainact.putextra(constants.get_timer_value,string.valueof(minremaining));         sendbroadcast(notifymainact);     } 

this broadcastreceiver in mainactivity.

 private broadcastreceiver timercountreceiver = new broadcastreceiver() {     @override     public void onreceive(context context, intent intent) {         log.i(tag, "on receiving intent");         string action = intent.getaction();         log.i(tag, action);         if(action.equalsignorecase(constants.broadcast_action)) {             string timercount = intent.getextras().getstring(constants.get_timer_value);             log.i(tag, " timer count received in activity "+timercount);             time_remaining.settext(timercount);          }         else if(action.equalsignorecase(constants.time_over)){             usr_msg.settext("time over");         }     } }; 

this manifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tony">  <uses-permission android:name="android.permission.internet" /> <application     android:allowbackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:supportsrtl="true"     android:theme="@style/apptheme">     <activity android:name=".mainactivity">          <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     <service         android:name=".timerservice"         android:enabled="true"         android:exported="false">     </service> </application> 

this minor thing.i had forgotten register intent actions while registering broadcastreceiver inside onresume() method.

@override public void onresume(){     super.onresume();     intentfilter receiverfilter = new intentfilter();     receiverfilter.addaction(constants.broadcast_action);     receiverfilter.addaction(constants.time_over_action);     registerreceiver(timercountreceiver, receiverfilter);  } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -