android


How to pause a thread after n minutes


I am using runnable and handler. I want to rotate the view at the same time.
This is my source:
public void rotateImage(final View myView, final int size) {
myHandler = new Handler();
runnable = new Runnable() {
#Override
public void run() {
int time = (2 * 60 * 1000) / 150;
if (size > time) {
myHandler.removeCallbacks(this);
return;
}
myView.setRotation(myView.getRotation() + size);
rotateImage(myView, size);
}
};
myHandler.postDelayed(runnable, 150);
}
It's working, and I can rotate the view every 150 milliseconds, but now I want to pause/stop the thread, for example after two minutes.
How can I do that?
you can calculate the number of iteration you need to get to 2mins, and change you runnable this way
#Override
public void run() {
if (currentIteration > mTotalIterations) {
myHandler.removeCallbacks(this);
currentIteration = 0;
return;
}
++currentIteration;
myView.setRotation(myView.getRotation() + size);
rotateImage(myView, size);
myHandler.postDelayed(this, 150);
}
you have to create only one runnable and only one handler

Related Links

Align menu item at Navigation to the right side in android
Recycler view only updating first visible position with onBind code?
Most efficient method of creating a local notification system with Firebase
Dagger 2: How properly to reuse dependency - how to design components and scopes?
Dophin browser on android fail to recognize deep linking
Unable to start Service after App startup
GSON: convert JSON with null array field into empty array
Navigation from one webview to another
Unable to add Window, Token is not valid error when clicked on a Spinner
PendingResult.setResultCallback() always returns the statusCode success
SwipeMenuListView new Row added is showing First time data
Android: “Element intent-filter is not allowed here” inside <provider>?
'onCharacteristicChanged' only get called in Debug mode and not when I run the app
Unity 3d PowerBar
Save Adjusted LayoutParams Imageview
Send SMS to self and receive it

Categories

HOME
batch-file
xml
cobalt
deep-learning
spark-streaming
ng-idle
static
apache-spark-mllib
saml-2.0
apiblueprint
nuget
pdfbox
google-cloud-functions
nsbundle
permissions
jetty
mvc5
crystal-lang
okhttp
project
drop-down-menu
gson
siddhi
tput
google-content-api
html5-appcache
sigma.js
oledb
sar
interpreter
definitelytyped
angularjs-components
mat
underscore.js
subclass
tizen-tv
google-earth
custom-controls
glib
r-grid
autolisp
nested-lists
arduino-ide
slacktextviewcontroller
ods
loading
demo
tasm
visa
levenshtein-distance
bindingnavigator
drupal-theming
hammer.js
manova
context-switch
qtranslate
truezip
reporting-services-2012
qiime
yajsw
asyncdisplaykit
sciruby
keyup
zend-currency
broadband
dbaccess
packet-sniffers
formview
strawberry-perl
named-parameters
kissfft
grails-plugin-rabbitmq
ios8-extension
android-framework
file-not-found
gd-graph
workitem
cascadingdropdown
resource-management
dopostback
monotouch.dialog
thttpd
kqueue
convention
denied
screen-size
google-floodlight
drawtobitmap
umra
strsep
timthumb
codebase
tabpanel
strtod
glui
lalr
scrubyt
wysiwym
netbeans6.1

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App