Hi folks!
I'm currently developing an app in android that is accessing wifi values, that is, the application needs to scan for all access point and their specific signal strengths.
I know that I have to extend the class BroadcastReceiver
overwriting the method BroadcastReceiver.onReceive(Context context, Intent intent)
which is called when the values are ready.
Perhaps there exist solutions provided by the android system itself but I'm relatively new to android so I could need some help.
The problem I encountered is that I got one class (an activity, thus controlled by the user) that needs this scan results for two different things (first to save the values in a database or second, to use them for further calculations but not both at one moment!)
So how to design the callback system in order to "transport" the scan results from onReceive(Context context, Intent intent)
to the operation intended by the user?
My first solution was to define enums for each use case (save or use for calculations) which wlan-interested classes have to submit when querying for the values. But that would force the BroadcastReceiver
extending class to save the current enum and use it as a parameter in the callback function of the querying class (this querying class needs to know what it asked for when getting backcalled)
But that seems to me kind of dirty ;)
So anyone a good idea for this?
views:
44answers:
1
A:
You probably want to use an anonymous inner class in each activity and/or an instance of a derived BroadcastReciever
in each activity and register it with Context#registerReceiver
. Then have it interact with it's parent when onRecieve
is called. What I think you're trying to do is define a BroadcastReciever
in your manifest file and then pass data on to an activity that way. Which is not the best way to achieve what you want.
Qberticus
2010-06-16 22:53:26
I think you misunderstood my question. I'd like to have the scanning process seperated completely from the GUI activity. The GUI owns an object, which offers methods to obtain values calculated by using wlan values. That means the object owned by the GUI shall start some kind of service or thread to scan for wlan values, which then calls back or notifies all listeners waiting for some kind of "values ready" signal. The problem is, that I have to handle several parameters like "number of scans", "how to scan", etc. at one time which the GUI doesn't know any more (as it gets called back)
Franz Xaver
2010-06-22 13:46:02