As i am making an app, there is problem in delay of the function,
Firstly I am using thread as a timer and I am also using an animation function....
When the timer ends it starts TextToSpeech and in background the animation of Images works continuosly...
After TTS ends it again starts the timer and after a fixed time timer stops and TTS is started..This works on continuosly..
But due to this there is problem in delay of TTS and it does not work exactly after the timer stops....and it takes some time....
So what should I do to stop this delay??
Thanks in advance
Your timer shouldnt have a fixed value, but a calculated one. If you want it to fire at a fixed internal (timeFI), you should calculate the processing time in the TTS (timeTTS) and set the timer "sleep time" = (timeFI - timeTTS)
Related
How to create a timer runed in the background and display one second of a second in the TextView dynamically in MainActivity.Whatever I exit app or leaving the MainActivity,the timer also keep on.
I thinked that I can use service and BroadcastReceiver or using Handler and Thread.But I can't solve it.
Having an always-on service to simply count up seconds is a bad idea, it'll waste battery life and could be killed at any time.
What you could do is something like this:
Make a counter that you can start/stop with a button.
On your your activity's onPause, save the System.currentTimeInMillis() along with the current count on your timer
When you resume your activity, use the current System.currentTimeInMillis() value to calculate what your timer should be displaying had it been really running all that time.
I have thinked a solution; Thread+Handler; EveryTime enter ther MainActivity
we just set the time interval = EndTime-System.currentTimeMillis();
In my android app, there is a SurfaceView. Whenever user touches it a short( 1 sec) animation is rendered on the SurfaceView by a AsyncTask. I face force close problem in two scenarios.
When used presses Back key while the animation is running.
In the arcade mode game duration is of 60 seconds. At the end of game, new activity is started. If at the end of the game , the animation is still running while the new activity is started, I get force close error message.
How can I check if the AsyncTask is complete i.e. the animation is over, before Back key press takes effect or new activity is started ? Using AsyncTask.getStatus() in a while loop is freezing the app. Or is there any alternative way to do this?
One of the way to wait for it to finish is like asyncTask.execute().get() ;
with this your main thread will wait this to finish
I'm new user of App inventor. I need small stopwatch. Basic function:
- set time ex. 25 min (if time=0;alarm=true)
- start time
- reset time (if you want reset time you will see the comfir box (yes or no)
Can anybody show me what block I must use to create it ?. Sorry for my English.
Here is a link to a discussed about this in the App Inventor Coffee Shop.
https://groups.google.com/forum/?fromgroups#!topic/appinventor/qrhfCSv4US0
This block will need a label, and a timer.
You can choose to make it in seconds or milliseconds by changing the clock functions.
Here is an example. The user enters the duration into the minute and second textboxes. Then they press the button. The timer interval is set to the duration converted to milliseconds. Then the timer is enabled. After the duration is up, Clock1.timer fires. The notifier shows an alert that the timer finished and the timer turns off. To reset the timer, just set Clock1.timerEnabled to true.
hey guys
I am trying to make a media player in which there is a seekbar.
Seekbar is running with a thread ; this thread is a runnable and not another class.
So far i have added the seekbar and now i want to stop the seekbar when pause button is pressed but there is nothing like :-
myThread.stop or myThread.pause??
Also i have to run one thread in background since if the user comes back to "now Playing"
activity he can see the seekbar at correct position
Thread is holding me back
Thanks
pause and stop and all those other methods don't exist any more (for very good reasons).
what you want to do is let your thread sit in a loop and do whatever it is you want it to do. Put in some settable flags that you can control from outside that will let the thread exit when you're done with it.
Keep in mind that threads aren't re-usable. Once you have run a thread you can't run it again.
Also, the seek bar can be set to the correct position when the user returns to your activity (I assume you'll keep the music playing in the background). There's no need to waste resources updating the seekbar's position while the activity is not in display.
What about using the buffering update callback provided by MediaPlayer?
It doesn't seem reasonable to me to have a thread running in the background to do this.
I have a Timer which executes a TimerTask every 30 seconds. I only want the timer to launch a new TimerTask if the Activity is displayed i.e. if the user receives a phone call or launches a new activity the Timer will stop. I then need the Timer to restart when the Activity is re-launched and comes into focus.
Now this should be easy, I override the "onWindowFocusChanged(boolean hasFocus)" method and either start or stop the timer depending on the value of hasFocus. The way I start the timer is to create a new Timer object and TimerTask each time and the way I stop the Timer is to call the cancel() method on the Timer object and set timer to null.
My problem is this doesn't always work, if I launch the activity which has the Timer and switch orientations quickly (to start/stop the Activity) I find the Timer is not always cancelled and I end up with multiple Timers launching TimerTasks at an ever increasing rate.
Am I missing something obvious here? Any help would be greatly appreciated.
Thanks
When I see this, it's because I'm creating 2 CountDownTimers in my app. Because each timer can only read messages of type "1" [see http://www.devdaily.com/java/jwarehouse/android/core/java/android/os/CountDownTimer.java.shtml ], it appeared that I only had 1 timer while my app was running normally. I put a "timer.cancel()" in my onDestroy that took care of one of the timers, allowing the other timer to start receiving all the timing messages--long after the onDestroy had returned.
Canceling any existing timer before creating another took care of the lingering timer.
I had a similar problem, I ended up using post delayed in a Thread and avoided a Timer. Not really a fix though.