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

Where do I put the licensing code for my app? (Android)
Can't Acces to Fragment Widgets From FragmentActivity
Refresh Listview Item inside Activity A from Fragments B in MultiPan
Trouble with animating fragment transaction animation
ListView vanishes after repaint
App is not using custom theme
Set alpha value to text on Action.Bar when selected
android-studio project git private folder
Android: Changing ActionBar background color Hex code
Stop app from launching on AVD start
Android NFC: one activity to send and one to receive only
Disable highlight in ExpandableListView
Image doesn't show in ImageView
Noticeable lag while connecting to Google Play Services in Android Wear
How to initiate TTS in OnCreate method in android
Prolem with numbers and special characters when uploading files to server in Android

Categories

HOME
notepad++
hyperlink
ecmascript-6
gpu
pascal
jsf-2.2
gradient
seo
javacc
hugo
babeljs
iis-6
opengl-3
extjs4.2
pattern-matching
categorical-data
endeca
fhir
naivebayes
code-generation
comsol
zerobrane
dimensional-modeling
google-data-studio
identity-management
babel
systemtime
string-concatenation
expressionengine3
jquery-multiselect
constexpr
corenlp-server
scrollview
glib
rselenium
reverse
xajax
dm-script
opensmpp
visa
logback-groovy
tcc
fclose
convex-optimization
payara-micro
java-6
truezip
objectscript
branch-prediction
grails-plugin
parfor
centrifuge
iotivity
dup
delta
avspeechsynthesizer
project-organization
lz77
highland.js
libvlc
sapi
toolkit
canalyzer
canvg
aspectj-maven-plugin
jquery-forms-plugin
zxspectrum
dot.js
nodelist
theos
beatsmusic
rickshaw
formview
rmysql
mobility
named-parameters
square-bracket
multiautocompletetextview
android-audiorecord
observium
scringo
idn
dopostback
adobe-media-server
listitem
mbeans
w3c-geolocation
massive
collectionviewsource
nhprof
undefined-index
interprocess
wcf-instancing
fault-tolerance
pbcopy

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