Anyway to detect if Broadcast Receiver is registered?

by Sam » Fri, 12 Mar 2010 00:24:03 GMT


Sponsored Links
 Hi,

I'm using more than 1 instance of MapActivity in an application that
look different from each other. I'm running into an issue sometimes
when leaving a MapActivity doesn't unregister it's BroadcastReceiver
and going Back to resume the MapActivity page it tries to re-register
the receiver again, thus receiving an Exception that Receiver already
registered.

Anyone know of a way to tell if a Broadcastreceiver is registered and
is listening?

Sam

--



Anyway to detect if Broadcast Receiver is registered?

by jeffkpayne » Tue, 30 Mar 2010 03:10:14 GMT


 I was wondering the same thing.  In my case I have a BroadcastReceiver
implementation that calls
Context#unregisterReceiver(BroadcastReceiver) passing itself as the
arg after handling the Intent that it receives.  There is a small
chance that the receiver's onReceive(Context, Intent) method is called
more than once, since it is registered with multiple IntentFilters,
creating the potential for an IllegalArgumentException being thrown
from Context#unregisterReceiver(BroadcastReceiver).

In my case I can store a private synchronized member to check before
calling Context#unregisterReceiver(BroadcastReceiver), but it would be
much cleaner if the API provided a check method.




--


Sponsored Links


Other Threads

1. Calling wipeData from a service

I have an app which just has a service in it. So it doesnt have an
activity. I want to call the wipeData() api from it.
I have followed an example which sets up the DevicePolicyManager from
inside the onCreate of an Activity class. That works fine.

Q1: My example only works if the mDeviceAdminSample is created as
below. If I try to create the mDeviceAdminSample  using new
ComponentName((String pkg, String cls) then I dont get a popup window
asking the user to confirm the new policies. Do I have to create the
ComponentName using a context and a class?

mDeviceAdminSample = new ComponentName(this, DeviceAdminSample.class);
...
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
mDeviceAdminSample);

Q2: If I setup the device policy from one app, can I use those
policies from another app?
The problem seems to me to be the...
mDeviceAdminSample = new ComponentName(this, DeviceAdminSample.class);
If it has to be created using a context then how can you use it from
another app?

Q3: Basically I have an app with just a service and I dont know how I
can call wipeData from it. I dont know how to create the
mDeviceAdminSample to hook into policies that have already been
created.

Many thanks

-- 

2. UI -using the setText() method ?

Hi,

I have a TableLayout and I populate its columns (and rows) dynamically by 
calling the setText() method whenever the corresponding values are updated.

How can I be sure that the new value of a certain table location will fit into 
its allocated space to avoid any runtime errors ?

Thanks in advance,

Emre
                                          

-- 

3. Samsung Adopts ARM鈥檚 Next Generation Mali-T604 GPU

4. SQLite and XML

5. map can't load at specific places

6. Skype official for Android..

7. aplikasi Qur'an dgn terjemahan Indonesia