Looking feedback/evaluation of some code for custom extension

Hello, I am currently working on creating a custom extension for my app and I would like to hear some peoples thoughts and possibly get some feed back on using the Task Scheduler to call an event.

I’m am by no mean means new to programming but I primary work with C++ on micro controllers or VB.net in Windows. I have very little experience with Java and the only Android knowledge I have is from working with programs like Kodular.

Now, this code doesn’t have any real purpose other then for testing/determining if this was going to work, and it does work with Kodular…at least when testing live using the the companion app. So before I implement these methods into the extension I am creating, I figured it might be best if I ask here first since this is still pretty new to me and I’m really not sure what type of issues(if any) I may run into using the Scheduler in conjunction with multiple event blocks and global variables.

private Timer t = new Timer(); 
 private int myCounter = 0;

  @SimpleFunction(description = "")
  public  void countLoop() {         
        t = new Timer(); 
        TimerTask tt = new TimerTask() {  
        @Override  
            public void run() 
            { 
                RunOnUiThread(); 
            };  
        };  
        t.scheduleAtFixedRate(tt, 10000, 1000);
    }  
  
    private void RunOnUiThread(){
		activity.runOnUiThread(new Runnable()
		{ 
			@Override
			public void run() 
			{                         
				TimedOutEvent(myCounter);
			}
		});   
	}

    @SimpleEvent(description="Event that fires each time the scheduler runs is called")
    public void TimedOutEvent( int thisNumber){
        if (myCounter >= 3)
        {
            TimerInProgress = false;
            myCounter = 0;
            t.cancel();
            Done("Event Ended", myCounter);
        }
        else
        {  
            myCounter += 1;
            EventDispatcher.dispatchEvent(this, "TimedOutEvent", thisNumber);
        } 
    }

    @SimpleEvent(description="Event that fires when the timer expires due to counts")
    public void Done( String myString, int thisCount){
        EventDispatcher.dispatchEvent(this, "Done", myString, thisCount);  
        
    }

    @SimpleFunction(description = "reset the counter while the Scheduler is running")
    public void resetCounts(){
        myCounter = 0;
    }

I do not know, if you will run into issues, just test it…
Please also follow the naming conventions

Taifun

I think you will face some problems with this function :point_up: