android - What happens when two apps define same BroadcastReceiver class in their manifest? -


i have android library project broadcastreceiver class , scheduler class defines methods setting repeating pendingintent broadcastreceiver

//delay alarmmanager setrepeating method in seconds //id requestcode pendingintent public static void schedulebroadcast(context context,int delay,int id){     intent intent = new intent(context, superreceiver.class);     intent.putextra(key_delay, (long)(delay * 1000));     intent.putextra("app_name", context.getpackagename());     long timegap = (long)(delay * 1000);      pendingintent alarmintent = pendingintent.getbroadcast(context, id, intent, pendingintent.flag_cancel_current);     alarmmanager alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service);     alarmmanager.setrepeating(alarmmanager.rtc_wakeup,             system.currenttimemillis() + timegap, timegap,             alarmintent); } 

the receiver

@override public void onreceive(context context, intent intent) {     log.e("chirag-library","superreceiver received!");     long delay = intent.getlongextra(bscheduler.key_delay, -1);     log.e("chirag-library","delay "+delay+" ms");     log.e("chirag-library", "by app called  "+ intent.getstringextra("app_name"));     log.e("chirag-library",context.getpackagename()); }    

i using project dependency in 2 of apps define receiver in manifest in exact same way

        <receiver android:name="com.chirag.library.superreceiver"/> 

i call schedulebroadcast() both of apps different delay value.

in com.chirag.appone

bscheduler.schedulebroadcast(getapplicationcontext(), 10,111); 

in com.chirag.apptwo

bscheduler.schedulebroadcast(getapplicationcontext(), 60,999); 

is onreceive() called both apps when 1 of pendingintent fired?

is because pendingintents have same receiver intent?

logcat shows logs in onreceived fired @ same time seconds

09-21 10:04:19.746  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:04:19.746  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:04:19.746  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:04:19.746  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:05:06.987  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:05:06.987  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:05:06.987  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:05:06.987  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:06:04.427  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:06:04.427  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:06:04.427  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:06:04.427  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:06:40.666  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:06:40.666  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:06:40.666  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:06:40.666  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:06:40.682  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:06:40.682  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:06:40.682  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:06:40.682  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:07:40.766  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:07:40.766  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:07:40.766  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:07:40.766  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:07:40.774  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:07:40.774  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:07:40.775  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:07:40.775  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:08:19.745  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:08:19.745  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:08:19.745  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:08:19.745  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:08:19.754  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:08:19.754  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:08:19.754  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:08:19.754  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:09:19.742  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:09:19.742  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:09:19.742  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:09:19.742  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:09:19.751  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:09:19.751  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:09:19.751  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:09:19.751  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:10:19.843  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:10:19.843  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:10:19.843  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:10:19.843  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:10:19.853  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:10:19.853  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:10:19.853  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:10:19.853  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:11:19.971  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:11:19.971  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:11:19.971  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:11:19.971  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:11:19.979  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:11:19.979  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:11:19.979  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:11:19.980  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:12:20.065  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:12:20.065  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:12:20.066  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:12:20.068  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:12:20.075  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:12:20.075  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:12:20.076  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:12:20.076  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 09-21 10:13:20.165  14673-14673/com.chirag.apptwo e/chirag-library﹕ superreceiver received! 09-21 10:13:20.165  14673-14673/com.chirag.apptwo e/chirag-library﹕ delay 60000 ms 09-21 10:13:20.165  14673-14673/com.chirag.apptwo e/chirag-library﹕ app called  com.chirag.apptwo 09-21 10:13:20.165  14673-14673/com.chirag.apptwo e/chirag-library﹕ com.chirag.apptwo 09-21 10:13:20.171  14306-14306/com.chirag.appone e/chirag-library﹕ superreceiver received! 09-21 10:13:20.171  14306-14306/com.chirag.appone e/chirag-library﹕ delay 10000 ms 09-21 10:13:20.171  14306-14306/com.chirag.appone e/chirag-library﹕ app called  com.chirag.appone 09-21 10:13:20.171  14306-14306/com.chirag.appone e/chirag-library﹕ com.chirag.appone 

what more confusing me why 10s delay appone fired once between 60s delay apptwo?

what happening here?

is onreceive() called both apps when 1 of pendingintent fired?

no. here's why: intent fed pendingintent explicit intent , makes onreceive application context specific , hence both apps have own receiver same name.

what more confusing me why 10s delay appone fired once between 60s delay apptwo?

after bug research on setrepeating() , found https://code.google.com/p/android/issues/detail?id=161244

which says on api >= 21 setrepeating() interval value reset 60s if less 60s(this not documented) happened case.

hence first time seem fire off @ different time intervals(currenttime + 10s , currenttime + 60s respectively) , later both fired @ intervals of 60s.also setrepeating() not yield seconds accurate events both of onreceive seemed fired @ same time leading confusion


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -