Created
February 16, 2014 23:13
-
-
Save akalipetis/9042015 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<receiver android:name="com.akalipetis.android.testing_demo.MyReceiver"> | |
<intent-filter> | |
<action android:name="my.custom.action"/> | |
</intent-filter> | |
</receiver> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
private BroadcastReceiver mReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
// TODO Act when in foreground here | |
abortBroadcast(); | |
} | |
}; | |
private IntentFilter mFilter = new IntentFilter("my.custom.action"); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); | |
} | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
registerReceiver(mReceiver, mFilter); | |
} | |
@Override | |
protected void onStop() { | |
super.onStop(); | |
unregisterReceiver(mReceiver); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
// TODO Implement action when not in foreground here | |
} | |
} |
Intent intent = new Intent();
intent.setAction("my.custom.action");
sendOrderedBroadcast(intent,null);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you also add on how to send the broadcast?
sendOrderedBroadcast()