Last active
May 30, 2018 09:37
-
-
Save chandruark/c721be8cba208898158e6158b062a29d to your computer and use it in GitHub Desktop.
This file contains 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 SampleActivity extends AppCompatActivity { | |
/** | |
* Sample Snippet for Registering Receiver | |
*/ | |
MyBroadcastReceiver myBroadCastReceiver; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_sample); | |
myBroadCastReceiver=new MyBroadCastReceiver(); | |
} | |
@Override | |
protected void onResume() { | |
/** | |
* Here you can register the receiver | |
*/ | |
registerBroadcastReceiver(); | |
super.onResume(); | |
} | |
private void registerBroadcastReceiver() { | |
/** | |
* Defining Intent Filters | |
*/ | |
IntentFilter intentFilter=new IntentFilter(); | |
intentFilter.addAction("android.intent.action.BOOT_COMPLETED"); | |
intentFilter.addAction("android.intent.action.QUICKBOOT_POWERON"); | |
registerReceiver(myBroadCastReceiver,intentFilter); | |
} | |
/** | |
* Unregistering Receiver is not used in our case , because | |
* we need to set repeatly ,even though after app ondestroy state | |
*/ | |
private void unregisterBroadcastReceiver() { | |
/** | |
* Unregistering Receiver | |
*/ | |
unregisterReceiver(myBroadCastReceiver); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment