Note that there are some explanatory texts on larger screens.

plurals
  1. POResched. timer after cancel gives "java.lang.IllegalStateException: Timer cancelled."
    primarykey
    data
    text
    <p>i would like to know whether i can schedule the timer again after i cancelled it. It was stated here, <a href="http://www.coderanch.com/t/452066/java/java/Exception-timer-IllegalStateException">http://www.coderanch.com/t/452066/java/java/Exception-timer-IllegalStateException</a>, 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, <strong>java.lang.IllegalStateException: Timer was cancelled.</strong> 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?</p> <p>Forgotten to mentioned that i would start the timer only after i finished loading images which i used AsyncTask to do that.</p> <p><strong>I trying to achieved this one a separate thread so that it would not hold up the UI thread.</strong></p> <p>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 "<strong><em>load.execute(context);</em></strong>"):</p> <pre><code>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&lt;ScanResult&gt; sc = wifi.getScanResults(); for(int i=0; i&lt;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&lt;Context, Void, ArrayList&lt;Bitmap&gt;&gt;{...} } </code></pre> <p>Uses Permission that was included:</p> <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt; &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.DELETE_CACHE_FILES"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; </code></pre> <p>Error encounter for the Broadcast receiver:</p> <pre><code>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.&lt;init&gt;(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) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload