The method you are trying to use is good! Without code, although it will be hard to say what you can do wrong.
In your service you will broadcast such an intention ...
private final void sendServiceActiveBroadcast( final boolean pActivate ) { final Intent _intent = new Intent(); _intent.setAction( "com.yourtld.android.SERVICE_BROADCAST" ); _intent.addCategory( "com.yourtld.android.CATEGORY" ); _intent.putExtra( "isactive", pActivate ); this.sendBroadcast( _intent ); }
then in your activity you could be something like ...
Create an action line:
private static final String SERVICE_BROADCAST_ACTION = "com.yourtld.android.SERVICE_BROADCAST";
In your onResume () method you will have ...
final IntentFilter serviceActiveFilter = new IntentFilter( SERVICE_BROADCAST_ACTION ); serviceActiveFilter.addCategory( "com.yourtld.android.CATEGORY" ); this.serviceReceiver = new BroadcastReceiver() { @Override public void onReceive( final Context context, final Intent intent ) { if( intent != null ) { if( intent.getBooleanExtra( "isactive", false ) ) {
Hope that helps
source share