Delay Extension

I need a way to wait a certain amount of time before doing the next event. Does anyone have an extension for delaying or waiting a X amount of time? Or if someone could make one and post it here that would be helpful!

1 Like

Can anyone help me fix this?

package com.niotron.WaitFunction;

import android.app.Activity;

import android.content.Context;

import com.google.appinventor.components.annotations.*;

import com.google.appinventor.components.common.ComponentCategory;

import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;

import com.google.appinventor.components.runtime.ComponentContainer;

import com.google.appinventor.components.runtime.EventDispatcher;

@DesignerComponent(

        version = 1,

        description = "waits a amount of time.",

        category = ComponentCategory.EXTENSION,

        nonVisible = true,

        iconName = "")

(@)SimpleObject(external = true)

//Libraries

(@)UsesLibraries(libraries = "")

//Permissions

(@)UsesPermissions(permissionNames = "")

public class WaitFunction extends AndroidNonvisibleComponent {

    //Activity and Context

    private Context context;

    private Activity activity;

    public WaitFunction(ComponentContainer container){

        super(container.$form());

        this.activity = container.$context();

        this.context = container.$context();

    }

@SimpleFunction()

public Object DelayPass( int TimeOut, Object DataToPass ) {

  try {

    TimeUnit.MILLISECONDS.sleep(TimeOut);

    } 

    catch (InterruptedException e) { 

    }    

  return DataToPass;

}

@SimpleFunction()

public void Delay(int TimeOut) { 

  try {

    TimeUnit.MILLISECONDS.sleep(TimeOut);

    }

    catch (InterruptedException e) {

    }

}

Started Compiling Project WaitFunction
Buildfile: /compiler/androidX/build.xml
javac:
[mkdir] Created dir: /compiler/androidX/build/UZOYr/classes
[javac] Compiling 1 source file to /compiler/androidX/build/UZOYr/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /compiler/androidX/src/UZOYr/com/niotron/WaitFunction/WaitFunction.java:55: error: reached end of file while parsing
[javac] }
[javac] ^
[javac] 1 error
[javac] 1 warning

1 Like
package com.niotron.WaitFunction;

import android.app.Activity;

import android.content.Context;

import com.google.appinventor.components.annotations.*;

import com.google.appinventor.components.common.ComponentCategory;

import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;

import com.google.appinventor.components.runtime.ComponentContainer;

import com.google.appinventor.components.runtime.EventDispatcher;

@DesignerComponent(

        version = 1,

        description = "waits a amount of time.",

        category = ComponentCategory.EXTENSION,

        nonVisible = true,

        iconName = "")

(@)SimpleObject(external = true)

//Libraries

(@)UsesLibraries(libraries = "")

//Permissions

(@)UsesPermissions(permissionNames = "")

public class WaitFunction extends AndroidNonvisibleComponent {

    //Activity and Context

    private Context context;

    private Activity activity;

    public WaitFunction(ComponentContainer container){

        super(container.$form());

        this.activity = container.$context();

        this.context = container.$context();

    }

@SimpleFunction()

public Object DelayPass( int TimeOut, Object DataToPass ) {

  try {

    TimeUnit.MILLISECONDS.sleep(TimeOut);

    } 

    catch (InterruptedException e) { 

    }    

  return DataToPass;

}

@SimpleFunction()

public void Delay(int TimeOut) { 

  try {

    TimeUnit.MILLISECONDS.sleep(TimeOut);

    }

    catch (InterruptedException e) {

    }

}

}

Try this code

But why don’t you use in-built clock component, which is more convenient and easy to use

Try this inbuilt component

I did not realize this existed, but after more searching and studying it I was able to geth the clock component working for what I needed. Thank you for your help!

Your most welcome dear :slightly_smiling_face:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.