broadcastreceiver - programmatic vs static broadcast recievers in android -


in app, utilizing gcm , push notifications. however, bit concerned regarding broadcast receivers. in app, see broadcast receivers being declared 2 types.

  1. static via manifest

       <receiver     android:name="com.google.android.gcm.gcmbroadcastreceiver"     android:permission="com.google.android.c2dm.permission.send" >     <intent-filter>         <action android:name="com.google.android.c2dm.intent.receive" />         <action android:name="com.google.android.c2dm.intent.registration" />         <category android:name="com.myapp" />     </intent-filter> </receiver>  <uses-permission android:name="android.permission.wake_lock" /> 
  2. programmatic inside activiy

       private final broadcastreceiver mhandlemessagereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) {      string newmessage = intent.getextras().getstring(extra_message);      wakelocker.acquire(getapplicationcontext());      toast.maketext(getapplicationcontext(), "new message: " + newmessage, toast.length_long).show();      wakelocker.release(); }  }; 

my questions follows :

question 1 : can remove programmatic declaration of broadcast receiver , still totally valid notification ? if yes, reason because have in manifest ?

question 2 : if receiver declared both static , programmatic, 1 called when ? 1 has priority ? if app open , running programmatic 1 gets called ? , in case app not running, static 1 ?

question #1 makes no sense me, sorry.

if receiver declared both static , programmatic, 1 called when ?

if both have intentfilters match same broadcast, both receive broadcast. regular broadcasts, order in receive broadcast indeterminate.

which 1 has priority ?

for regular broadcasts, neither have "the priority" -- both broadcast, , have no way of knowing gets first (and on multi-core devices, broadcast @ same time, in theory). ordered broadcasts allow control priority of delivery, , 1 of receivers ordered broadcast @ time.

if app open , running programmatic 1 gets called ?

if "the app open , running" means have receiver registered via registerreceiver() and manifest, both receive broadcast.

and in case app not running, static 1 ?

if "not running" means have unregistered receiver registered via registerreceiver(), receiver registered in manifest receive broadcast.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -