BroadcastReceiver registration is quite simple for and application. This example will show you how to register it from widget.
Es an example we will register receiver for ACTION_TIME_TICK intent.
We do not need to register it on AndroidManifest.xml because ACTION_TIME_TICK intent can't be registered in manifest.
First of all you need to create a BroadcastReceiver class instance.
private BroadcastReceiver HelloReceiver = new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent intent) { //do something on receive } };
Register our receiver in WidgetProvider class onUpdate method.
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetId) { context.getApplicationContext().registerReceiver(this.HelloReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); //do other actions such as update widget... }
The main point of this example that we are using a context.getApplicationContext() method to get a context instead of context that passed to onUpdate()
Have a nice code!
This is completely unreliable. Android will terminate your process whenever it wants after the onUpdate() method returns, causing the BroadcastReceiver and Application to both vanish.
ReplyDeleteThanks for your comment, but currently it works perfect for me :) And I didn't find a better solution for now!
ReplyDeleteThanks Yaroslav Martsynyuk, Please tell me how to unregister?
ReplyDeleteYour very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
ReplyDeleteindustrial course in chennai
great stuff, thanks for the blog
ReplyDeleteGerman Classes in Chennai
Big Data Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
JAVA Training in Chennai
Java training in velachery
This comment has been removed by the author.
ReplyDeleteThanks for sharing and i think it's very useful content so please keep sharing such type of content.
ReplyDeleteUnderstanding Lifecycle in Android Activity
I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
ReplyDeletedata science training in chennai
data science training in tambaram
android training in chennai
android training in tambaram
devops training in chennai
devops training in tambaram
artificial intelligence training in chennai
artificial intelligence training in tambaram
The strategy you have posted on this technology helped me to get into the next level and had lot of information in it..
ReplyDeleteweb designing training in chennai
web designing training in omr
digital marketing training in chennai
digital marketing training in omr
rpa training in chennai
rpa training in omr
tally training in chennai
tally training in omr
Hello Beautiful people?
ReplyDeleteI think you are looking perfect logo design for your company right?
Buy a logo 5O% off. Custom Logo
MMORPG OYUNLAR
ReplyDeleteinstagram takipçi satın al
tiktok jeton hilesi
Tiktok Jeton Hilesi
antalya saç ekimi
referans kimliği nedir
instagram takipçi satın al
Mt2 Pvp
instagram takipçi satın al