timertask

Timer/TimerTask Error

情到浓时终转凉″ 提交于 2019-12-08 13:34:34
问题 I just started with programming of android applications and right now I have a problem with timer and timer tasks. In my app I use a timer to update the UI but when I start to test it gets an error and I have to force close it. Here is my timer code: int delay = 5000; // delay for 5 sec. int period = 1000; // repeat every sec. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { moveLettersInCircle(); } }, delay, period); Logcat says this: 07-30 18:40:12

How to Stop Timer Android

喜夏-厌秋 提交于 2019-12-08 08:13:16
问题 following is my code: In MainActivity.class private OnCheckedChangeListener alert_on_off_listener = new OnCheckedChangeListener(){ public void onCheckedChanged(RadioGroup groupname, int CheckedButtonId) { if(CheckedButtonId==R.id.radiobutton_on){ Toast.makeText(getApplicationContext(), "radio on", Toast.LENGTH_LONG).show(); alert_on = true; display_alert(); } else{ alert_on = false; } } }; public void display_alert(){ int delay = 10000; Timer timer =new Timer(); timer.scheduleAtFixedRate(new

Service and IntentService, Which is better to run a service that poll database value from the server?

放肆的年华 提交于 2019-12-07 23:50:56
问题 I had read quite a number of resources regarding the Service and IntentService . However when come to make a decision, I am not confident enough to choose which type to use in order to create a background service that will poll data from database in a time interval and stop it when I get the data I want since the data represent a status of a request, eg. ordering medicine confirmation status(pending, completed, in progress). I need to detect when a status is set to "completed" and send a

video & image viewPager

爱⌒轻易说出口 提交于 2019-12-06 18:12:26
I have a problem in my code can anyone help me? I need to make app play story like Messenger app I want to display a list of images and videos in viewpager automatically or manually I do it but I faced some problem First: when page of image is view and the next page play video the sound of video is playing when view the image because the pager load the next fragment i used mViewPager.setOffscreenPageLimit(0); but i didn't do any thing Second one: when I move manually from video to image the video not stop playing when I search for a solution I found this: public void setUserVisibleHint(boolean

TimerTask can't update the JavaFX Label text

假如想象 提交于 2019-12-06 09:59:10
I have a fairly simple JavaFX GUI application which has an label that shows how much time is left until a certain action starts. To achieve this, I've created a DownloadTimer class as shown below: public class DownloadTimer(){ private int minutes; private int seconds; private Timer innerTimer = new Timer(); private TimerTask innerTask; private boolean isActive; public DownloadTimer(int minutes, int seconds) { if (seconds > 60) { int minToAdd = seconds / 60; this.minutes = minutes; this.minutes += minToAdd; this.seconds = seconds % 60; } else { this.minutes = minutes; this.seconds = seconds; }

Service and IntentService, Which is better to run a service that poll database value from the server?

一笑奈何 提交于 2019-12-06 08:31:18
I had read quite a number of resources regarding the Service and IntentService . However when come to make a decision, I am not confident enough to choose which type to use in order to create a background service that will poll data from database in a time interval and stop it when I get the data I want since the data represent a status of a request, eg. ordering medicine confirmation status(pending, completed, in progress). I need to detect when a status is set to "completed" and send a notification to alert the user that the order is completed. After that the service will stop itself

Android: TimerTask scheduled for repetition getting fired only once

为君一笑 提交于 2019-12-06 03:19:35
问题 Ok this is a very weird problem I am having, and I'm pretty sure that I am messing up somewhere, but I can't quite figure out where. What I am trying is - Schedule a Timer to execute a TimerTask every five seconds The TimerTask in turn executes an AsyncTask (which in this case simple sleeps for a second before returning the static count of the number of AsyncTasks). Finally, the aforementioned count is updated in the UI. And of course, the appropriate Handler s and Runnable s have been used

How to cancel timerTask for AsyncTask in android

夙愿已清 提交于 2019-12-06 02:17:55
Hi I am working on TCP socket. I can read data for every 1 sec. to achieve it I used TimerTask as shown in below code. Handler handler = new Handler(); Timer timer = new Timer(); TimerTask doAsynchronousTask = new TimerTask() { @Override public void run() { finalizer = new Runnable() { public void run() { try { if (navBool) { runOnUiThread(new Runnable() { public void run() { new RetriveStock().execute(); // AsyncTask. } }); } } catch (Exception e) { } } }; handler.post(finalizer); } }; timer.schedule(doAsynchronousTask, 0, 1000); For canceling this timer I used code as timer.cancel(); timer =

How to implement a efficient timeout in java

前提是你 提交于 2019-12-05 02:14:32
问题 There are n object which perform some actions. After performing an action a timestamp will be updated. Now I want to implement a timeout-thread which verifies if a timestamp is older than for example 60 seconds. My first solution was to do that with a thread (while-loop + sleep) which is holding a list with all objects including the last timestamp. Now I have the problem that there is a worst-case scenario where the thread needs 59 seconds plus sleep time to decide for a timeout. I’m

Getting metadata from SHOUTcast using IcyStreamMeta

半腔热情 提交于 2019-12-05 01:38:28
问题 I am writing an app for Android that grabs meta data from SHOUTcast mp3 streams. I am using a pretty nifty class I found online that I slightly modified, but I am still having 2 problems. 1) I have to continuously ping the server to update the metadata using a TimerTask. I am not fond of this approach but it was all I could think of. 2) There is a metric tonne of garbage collection while my app is running. Removing the TimerTask got rid of the garbage collection issue so I am not sure if I am