JavaScript Alternatives Method SetInterval and ClearInterval in Android

JavaScript Alternatives Method SetInterval and ClearInterval in Android

Javascript Setinterval

Hello Friends as We know Switching from Web Developers to Android we Stuck in Some Situation of Methods and How we use Such Methods.

Here i Give a simple Method of JavaScript Which is.

SetInterval = for Creating Task Multiple Times Until we Not Stop it.
Clearinterval = For Stoping SetInterval Task.

Lets Create a Demo page and see How it Works?

<!DOCTYPE html>
 <title>Set Interval and Clear interval in JavaScript</title>
<p>Example of Set interval and Clear interval</p>
<div id="data">
<script type="text/javascript">
 var myHtmlDiv=document.getElementById("data");
 var loop=0;
 var s=setInterval(function(){
  myHtmlDiv.innerHTML+='A Text After 1 seconds <br>';
   //stop my setinterval function after 10 times if you want infinte times executing then remove the if condition means no clearinterval method

Result :

Javascript Setinterval

Now Lets How We Use this Methods in Android?

So We Can use This Method Simply in Android by Using this Methods

      final Timer timer= new Timer();
        timer.scheduleAtFixedRate(new TimerTask(){
            public void run(){
                Log.i("tag", "A Kiss every 5 seconds");
Previous Post
Next Post

post written by: