Chris
Chris

Reputation: 85

Reloading Webview User Defined Timer String

I have a webview where a user will choose the amount of time it will automatically update (as well as a choice of content). I can't seem to get the timer to recognize a string. Any thoughts? I know there has to be an easy way to do this.

Here is the code that is NOT Working. However, it I replace the variable with a static number, it works fine. Just need it to get to work with that string.

      SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
      String q = SP.getString("appViewType","http://www.google.com");
      String c = SP.getString("appRefreshRate","20");

      webview = (WebView) findViewById(R.id.scroll);
      webview.getSettings().setJavaScriptEnabled(true);
      webview.setWebViewClient(new QuotesWebView(this));
      webview.loadUrl(q);

      ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();

                timer.scheduleAtFixedRate(new Runnable() {

                          @Override
                          public void run() {
                                    webview.reload();
                          }

                }, 10, c, TimeUnit.SECONDS);

Upvotes: 1

Views: 1271

Answers (1)

MGK
MGK

Reputation: 7098

I guess you should convert your string to long value

timer.scheduleAtFixedRate(new Runnable() {

             @Override
             public void run() {
             webview.reload();
             }

     }, 10, Long.parseLong(c),TimeUnit.SECONDS);

Upvotes: 2

Related Questions