postdelayed

Self-updating every 10 seconds widget Handler.postDelayed problem

不想你离开。 提交于 2019-12-12 14:10:32
问题 I'm trying to make work a self-updating functionality in an Android widget, something simple as changing two TextViews of it every 10 seconds. The ideal solution would be to make it similar to the genie widget (news & weather). And so far, it works okay: it updates every 10 seconds via Handler.postDelayed's Runnable. Runnable updateWidgetText = new Runnable() { @Override public void run() { if (screenEnabled) { AppWidgetManager gm = AppWidgetManager.getInstance(ctx); ComponentName thisWidget

Android Testing Handler.postDelayed

北慕城南 提交于 2019-12-12 07:14:55
问题 I'm newbie on Android and get stuck on testing a SplashScreen, basically what I'm doing is trying to test that the splash screen stays on for 3s. this is the code for the splashScreen @Override protected void onStart() { super.onStart(); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(SplashScreenActivity.this, MainActivity.class); startActivity(i); finish(); } }, SPLASH_TIME_OUT); } And this is my approach for the test: @Test public void

Handler.postDelayed running for extra time

冷暖自知 提交于 2019-12-06 15:17:37
问题 I am writing an handler to run for an fix amount(30 Sec) time. Basic on that it update counter to draw a view component. counterRunnable = new Runnable() { int currV = 0; public void run(){ if(count >= 360) { counterHandler.removeCallbacks(this); onTimerComplete(); } else { count++; counterHandler.postDelayed(this, 83); // (30/360) = ~83 } } }; As I am running back it for delay of 83ms for 360 time (83*360 = 29880ms ~30 Sec) but it is running for ~39 sec . Any suggestion if I am doing

Running a task at a specific time using postDelayed

守給你的承諾、 提交于 2019-12-06 02:41:07
I would like to start a task at a specific time. For that I use runnable and postDelayed method as follows: private Runnable mLaunchTask = new Runnable() { public void run() { try { MY TASK } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }; In my code I use mLunchTask as follows: mHandler = new Handler(); mHandler.postDelayed(mLaunchTask, myDelay*1000); and myDelay is computed as follows: s = DateFormat.format("hh:mm:ss aaa", d.getTime()); cTime = s.toString(); // current Time ch = Integer.parseInt(cTime.substring(0,2)); // current

Handler.postDelayed running for extra time

喜欢而已 提交于 2019-12-04 22:23:21
I am writing an handler to run for an fix amount(30 Sec) time. Basic on that it update counter to draw a view component. counterRunnable = new Runnable() { int currV = 0; public void run(){ if(count >= 360) { counterHandler.removeCallbacks(this); onTimerComplete(); } else { count++; counterHandler.postDelayed(this, 83); // (30/360) = ~83 } } }; As I am running back it for delay of 83ms for 360 time (83*360 = 29880ms ~30 Sec) but it is running for ~39 sec . Any suggestion if I am doing anything wrong. Analysis: I checked same with Timer (scheduled at fix rate) and it's performing better as

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

情到浓时终转凉″ 提交于 2019-12-04 18:17:55
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_x != new_x) { timedMoveIV(100); old_x = (int)img.getX(); } It calls this method which works if I do it

How to delay execution android

旧时模样 提交于 2019-12-03 16:55:57
问题 I am building an android board game which features AI. The AI gets a turn and has to invoke a series of actions after which it posts invalidate to my custom view to update. I need to slow down these actions so the user gets to see the AI having its turn rather than it flashing by. I have tried something along these lines try { doFirstThing(); Thread.sleep(500) //post invalidate doNextThing(); Thread.sleep(1000) //post invalidate } catch (Exception e) { } However this is having absolutely no

How to delay execution android

雨燕双飞 提交于 2019-12-03 06:05:56
I am building an android board game which features AI. The AI gets a turn and has to invoke a series of actions after which it posts invalidate to my custom view to update. I need to slow down these actions so the user gets to see the AI having its turn rather than it flashing by. I have tried something along these lines try { doFirstThing(); Thread.sleep(500) //post invalidate doNextThing(); Thread.sleep(1000) //post invalidate } catch (Exception e) { } However this is having absolutely no effect. Also this is running in a separate thread if this wasn't obvious. Whats my best option I've

make an IntentService not sleep until it executes a handler.postDelayed runnable

懵懂的女人 提交于 2019-12-02 06:23:12
问题 In the onHandleIntent of my my IntentService class, I created handle containing a runnable which should be done after 20 seconds. Unfortunatly my service sleeps or is destroyed before this period. I tried also with the CountDownTimer, but i had the same problem. Do someone have any idea can I make the onHnadleIntent waiting? Thank you! This is the code: public class MyService extends IntentService { //... @Override protected void onHandleIntent(Intent workIntent) { Handler handler = new

make an IntentService not sleep until it executes a handler.postDelayed runnable

一曲冷凌霜 提交于 2019-12-02 00:57:42
In the onHandleIntent of my my IntentService class, I created handle containing a runnable which should be done after 20 seconds. Unfortunatly my service sleeps or is destroyed before this period. I tried also with the CountDownTimer, but i had the same problem. Do someone have any idea can I make the onHnadleIntent waiting? Thank you! This is the code: public class MyService extends IntentService { //... @Override protected void onHandleIntent(Intent workIntent) { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Log.i("20 seconds later","I am