postdelayed

How to loop or execute a function every 5 seconds on Android

爱⌒轻易说出口 提交于 2020-01-20 19:32:45
问题 How can I loop that time() function on the onCreate every 5 seconds.. help me I'm a newbie in Android =) ... I want to execute time() function in onCreate every 5 seconds. public void onCreate(Bundle savedInstanceState) { time(); //<-- How can i execute this every 5 seconds. } private void time() { new Handler().postDelayed(new Runnable() { @Override public void run() { int success; gps = new GPSTracker(AdminMenu.this); if(gps.canGetLocation()){ tmplat=latitude; tmplong=longitude; // new

Stop handler.postDelayed()

不问归期 提交于 2020-01-18 13:22:23
问题 I call multiple Handlers by new Handler().postDelayed(new Runnable()..... How can I stop it when I click on back? public class MyActivity extends AppCompatActivity implements OnClickListener { private Button btn; private Handler handler; private Runnable myRunnable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); btn = (Button) findViewById(R.id.trainingsstart); btn.setOnClickListener(this); } @Override public void onClick(View v) { Handler

Stop handler.postDelayed()

会有一股神秘感。 提交于 2020-01-18 13:18:13
问题 I call multiple Handlers by new Handler().postDelayed(new Runnable()..... How can I stop it when I click on back? public class MyActivity extends AppCompatActivity implements OnClickListener { private Button btn; private Handler handler; private Runnable myRunnable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); btn = (Button) findViewById(R.id.trainingsstart); btn.setOnClickListener(this); } @Override public void onClick(View v) { Handler

Stop handler.postDelayed()

穿精又带淫゛_ 提交于 2020-01-18 13:18:03
问题 I call multiple Handlers by new Handler().postDelayed(new Runnable()..... How can I stop it when I click on back? public class MyActivity extends AppCompatActivity implements OnClickListener { private Button btn; private Handler handler; private Runnable myRunnable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); btn = (Button) findViewById(R.id.trainingsstart); btn.setOnClickListener(this); } @Override public void onClick(View v) { Handler

handler.postDelayed vs. AlarmManager vs

ぐ巨炮叔叔 提交于 2020-01-01 19:27:09
问题 I have a minor problem in one of my apps. It uses a BroadCastReceiver to detect when a call finishes and then performs some minor housekeeping tasks. These have to be delayed for a few seconds, to allow the user to see some data and to ensure that the call log has been updated. I'm currently using handler.postDelayed() for this purpose: public class CallEndReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { if (DebugFlags.LOG

Get remaining time when using handler.postDelayed

风格不统一 提交于 2019-12-24 01:48:18
问题 I am using handler.postDelayed method to create some delay for some animation stuff. Like this: Handler h = new Handler(); h.postDelayed(new Runnable() { @Override public void run() { // Start Animation. } }, 6000); Later, How can I get the remaining time until the animation starts? 回答1: You can simply save the time in a var when you call post delayed long startTime = System.nanoTime(); h.postDelayed(... and then when you need to check the remaining time you can calculate the elapsed time

Android postDelayed works but can't put it in a loop?

匆匆过客 提交于 2019-12-22 00:13:22
问题 Sorry I am a noob I've read countless tutorials about making a simple timer and was wondering why it doesn't work until I noticed it is the while-loop causing the issue o.O I have removed it and then it works but only 1 time I need to use the loop though so the movement finishes :C Heres the code: old_x is the coordinate from an ImageView and new_x from the onTouch Event, maybe the problem because I am casting them as an int? I don't know what I need to do so it works please help O: while(old

How to change/reset handler post delayed time?

妖精的绣舞 提交于 2019-12-18 02:43:28
问题 I'm using postDelayed method of the Handler in order to perform an action after certain amount of time: private static int time_to_wait = 2000; Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { // Make Action } }, time_to_wait); now in the middle of the waiting time i want to change the value of the remaining milliseconds due to some processing results, let's say it now waited 1000 ms and i want to make it begins to count from 2000 again, So, i set the

When exactly is onUserInteraction() called?

陌路散爱 提交于 2019-12-13 13:14:52
问题 in my app I got a thrad that checks every 60s data from a webservice (defined in onCreate()): new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(PERIOD); if(condition) do_something(); } catch (Exception e) { e.printStackTrace(); } } } }).start(); Additionally i got a handler executing a method after a period of user inactivity: private Handler disconnectHandler = new Handler(); private Runnable disconnectCallback = new Runnable() { @Override public

can not run countdowntimer at all

丶灬走出姿态 提交于 2019-12-13 02:58:08
问题 I have a problem with countdown timer.I try some of solutions and articles in this site but they never worked for me. so, please read my codes... also I used handler.postDelayed(new Runnable() { before and it was not my solution but it just worked correctly. Main question is: I want to do something like below: (button pressed) do some codes1 delay1 do other codes2 delay2 go back to *do some codes1* again. In short, this is my real code: itimesec--; setdelay(); irepeat--; setrelax(); and this