Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:37:56+00:00 2026-05-26T10:37:56+00:00

i would like to know whether i can schedule the timer again after i

  • 0

i would like to know whether i can schedule the timer again after i cancelled it. It was stated here, http://www.coderanch.com/t/452066/java/java/Exception-timer-IllegalStateException, that once you cancelled the timer, it would not be possible to scheduling anything on the same timer unless i create a new Timer. And also, i encountered the following error, java.lang.IllegalStateException: Timer was cancelled.
I am trying to come out with a Timer that would regularly perform Wifi scanning. But i wished to “pause” or if not, cancelled the timer when it is performing some calculation after scanning. Only then after it complete the calculation and return some results back, i would resume the Timer. Can anyone tell me how i can go about in getting this problem solved?

Forgotten to mentioned that i would start the timer only after i finished loading images which i used AsyncTask to do that.

I trying to achieved this one a separate thread so that it would not hold up the UI thread.

Here is the rough skeleton of the program and start timer where it would perform wifi scanning when time elasped only after the image have been loaded completely (after “load.execute(context);“):

public class LargeImageScroller extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(new SampleView(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {...}

@Override
public boolean onOptionsItemSelected(MenuItem item) {...}

//this is the class where the program would do all the UI and display images
private static class SampleView extends View {

    public SampleView(Context context) {
                    :
        loadMap load = new loadMap();
        load.execute(context);

        scanTask = new TimerTask(){

            @Override
            public void run() {
                // TODO Auto-generated method stub
               handler.post(new Runnable() {
                        public void run() {
                         wifi = (WifiManager)context.getSystemService(WIFI_SERVICE);
                         context.registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
                         wifi.startScan();
                         Log.d("TIMER", "Timer set off");
                        }
               });
            }

        };

        scanTimer.schedule(scanTask, refreshRate);
    }

    public class wifiReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            List<ScanResult> sc = wifi.getScanResults(); 
            for(int i=0; i<sc.size(); i++){
                Log.e("AndroidRuntime", sc.get(i).SSID);
            }
        }

    }
    public boolean onTouchEvent(MotionEvent event) {...}
    protected void onDraw(Canvas canvas) {...}
    private static Drawable LoadImageFromWebOperations(String url){...}
    private static Bitmap decodeFile(File f, int requiredSize){...}
    private class loadMap extends AsyncTask<Context, Void, ArrayList<Bitmap>>{...}
}

Uses Permission that was included:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.DELETE_CACHE_FILES"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Error encounter for the Broadcast receiver:

10-25 05:53:04.903: ERROR/ActivityThread(1551): Activity android.wps.LargeImageScroller has leaked IntentReceiver android.wps.LargeImageScroller$SampleView$wifiReceiver@43d1bca0 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-25 05:53:04.903: ERROR/ActivityThread(1551): android.app.IntentReceiverLeaked: Activity android.wps.LargeImageScroller has leaked IntentReceiver android.wps.LargeImageScroller$SampleView$wifiReceiver@43d1bca0 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:797)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:608)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.app.ApplicationContext.registerReceiverInternal(ApplicationContext.java:724)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:711)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:705)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:308)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.wps.LargeImageScroller$SampleView$1$1.run(LargeImageScroller.java:187)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.os.Handler.handleCallback(Handler.java:587)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.os.Looper.loop(Looper.java:123)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at android.app.ActivityThread.main(ActivityThread.java:4363)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at java.lang.reflect.Method.invokeNative(Native Method)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at java.lang.reflect.Method.invoke(Method.java:521)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-25 05:53:04.903: ERROR/ActivityThread(1551):     at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:37:56+00:00Added an answer on May 26, 2026 at 10:37 am

    @Alan Moore: Hi, i guess i finally did it! this is the code that was able to perform wifi scan and send back the response back to the calling activity using Broadcast intent.

    LargeImageScoll.java (Activity)

    Intent intent;
    
    public static Runnable scanTask;
    
    public BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            //updateUI(intent); 
            //String returnedValue = intent.getStringExtra("data");
            Bundle bundle = intent.getExtras();
            String returnedValue = bundle.getString("data");
            Log.e("Waht", returnedValue);
        }
    };
    
    private static Handler handler = new Handler(){
    
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            super.handleMessage(msg);
        }
    
    };
    
    public class LargeImageScroller extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(new SampleView(this));
    
            intent = new Intent(this, WifiScanning.class);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {...}
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {...}
    
    //this is the class where the program would do all the UI and display images
    private static class SampleView extends View {
    
        public SampleView(Context context) {
                    :
        loadMap load = new loadMap();
        load.execute(context);
    
        scanTask = new Runnable(){
        @Override
        public void run() {
        // TODO Auto-generated method stub
        startService(new Intent(context, WifiScanning.class));  
        };
    
        handler.removeCallbacks(scanTask);
        handler.postDelayed(scanTask, refreshRate);
    }
    
    public boolean onTouchEvent(MotionEvent event) {...}
    protected void onDraw(Canvas canvas) {...}
    private static Drawable LoadImageFromWebOperations(String url){...}
    private static Bitmap decodeFile(File f, int requiredSize){...}
    private class loadMap extends AsyncTask<Context, Void, ArrayList<Bitmap>>{...}
    
    }//end of SampleView
    
    protected void onResume() {
        // TODO Auto-generated method stub
        Log.e("AndroidRuntime", "onResume");
        handler.removeCallbacks(scanTask);
        handler.postDelayed(scanTask, refreshRate);
        registerReceiver(broadcastReceiver, new IntentFilter(WifiScanning.BROADCAST_ACTION));
        super.onResume();
    }
    
    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        Log.e("AndroidRuntime", "onStop");
        unregisterReceiver(broadcastReceiver);
        stopService(new Intent(this, WifiScanning.class));
        handler.removeCallbacks(scanTask);
        super.onStop();
    }
    }//end of LargeImageScroll
    

    WifiScanning.java (Service)

    public static final String BROADCAST_ACTION = "android.wps.wifiscanning.broadcasttest";
    int counter = 0;
    Intent intent1;
    WifiReceiver receiverWifi = new WifiReceiver();
    WifiManager wifi;
    StringBuilder sb;
    List<ScanResult> wifiList;
    
    public void onCreate() {
        super.onCreate();
    
        intent1 = new Intent(BROADCAST_ACTION); 
        Log.e(TAG, "Service creating");
        wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        if(counter==0){
        Log.e("AndroidRuntime", "Scan for the "+counter+" time");
        wifi.startScan();
        counter++;
        }
    }
    
    class WifiReceiver extends BroadcastReceiver {
        public void onReceive(Context c, Intent intent) {
            sb = new StringBuilder();
            wifiList = wifi.getScanResults();
            for(int i = 0; i < wifiList.size(); i++){
                sb.append("["+ (wifiList.get(i).SSID).toString() + "][");
                sb.append((wifiList.get(i).BSSID).toString() + "][");
                sb.append((String.valueOf(wifiList.get(i).level)) + "]");
                sb.append("\n");
            }
            Log.e("AndroidRuntime", sb.toString());
            if(counter<4){
                Log.e("AndroidRuntime", "Scan for the "+counter+" time");
                wifi.startScan();
                counter++;
            }else{
                intent1 = new Intent(BROADCAST_ACTION);
                String test = sb.toString();
                intent1.putExtra("data", test);
                sendBroadcast(intent1);
            }
        }
    }
    
    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        unregisterReceiver(receiverWifi);
        super.onDestroy();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know whether i can get the drive information using the
I would like to know whether I can use DL Query in Protege programatically.
I would like to know whether I can test some value against a condition
I would like to know whether I can get source code a method on
I would like to know whether something like this can be easily achieved, any
I would like to know whether there are software that a user can edit
I am new to JavaFx technology, I would like to know whether I can
I would like to know whether there is a jQuery function which can check
I would like know whether we can highlight text (colors) of already created PDF
I would like to know whether i can assume that same operations on same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.