As the question implies, I am wondering how I could write a thread
that would call a system service and then wait a certain amount of
time before calling said system service's function that calls back to
onReceive from a registered BroadcastReceiver.

In other words, I am trying to call the Wifi scanning service
(registering a BroadcastReceiver with IntentFilters) within my custom
local service so I can get the current SSID's available and send them
back to the activities that are bound to this service. I know what I
will end up doing with the received data, which is not relevant to
this question. However, I will need to wait a certain amount of time
before calling startScan again within onReceive, and that is where I
am trying to determine the best course of action.

Here is what I have so far:

        class MyWifiScanner extends BroadcastReceiver implements Runnable{
                private boolean running;
                private final int SLEEP_TIME = 10000;
                private Object mSync = new Object();
                WifiManager wifiMan;
                Thread t;
                public MyWifiScanner(){
                        //receiver registered with intent filters
                        wifiMan = (WifiManager)
SSIDListenerService.this.getSystemService(Context.WIFI_SERVICE);
                        t = new Thread(this);
                        t.start();
                }

                @Override
                public void onReceive(Context context, Intent intent) {
                        //Received WiFi access point names, handle them
                        //Should I call wait on a sync object while syncronized 
with it for
said amount of time and then call notify???
                        syncrhonized(mSync){
                                mSync.wait(SLEEP_TIME);
                                mSync.notify();
                        }
                }

                @Override
                public void run() {
                        while(running){
                                syncrhonized(mSync){
                                        wifiMan.startScan();
                                }
                        }

                }
        }

Or would it make sense to just create a BroadcastReceiver object that
just calls Thread.sleep in the end of onReceive?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to