Design problem with callback functions in android

Posted by Franz Xaver on Stack Overflow See other posts from Stack Overflow or by Franz Xaver
Published on 2010-06-16T22:39:51Z Indexed on 2010/06/16 22:42 UTC
Read the original article Hit count: 301

Filed under:
|
|

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 BroadcastReceiverextending 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?

© Stack Overflow or respective owner

Related posts about android

Related posts about design