I want to be able to call the following method after a specified delay. In objective c there was something like:
[self performSelector:@selector(DoSomething) withObject:nil afterDelay:5];
Is there an equivalent of this method in android with java? For example I need to be able to call a method after 5 seconds.
public void DoSomething() { //do something here }
You can use this for Simplest Solution: new Handler(). postDelayed(new Runnable() { @Override public void run() { //Write your code here } }, 5000); //Timer is in ms here.
To call a method in Java, you type the method's name, followed by brackets. This code simply prints “Hello world!” to the screen. Therefore, any time we write helloMethod(); in our code, it will show that message to the screen.
putBoolean("key",1); //or you can also use editor. putString("key","value"); editor. commit(); After doing so, say for example if user recalls an activity, then you check the value of in the shared prefs and if it is found, then just perform the action you wish to do else, allow the user to continue with the activity.
Handler(Looper.getMainLooper()).postDelayed({ //Do something after 100ms }, 100)
final Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(new Runnable() { @Override public void run() { //Do something after 100ms } }, 100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With