For Loop Until Button Is Pressed in Android - Stack Overflow PDF
For Loop Until Button Is Pressed in Android - Stack Overflow PDF
Questions
Tags
Users
sign up
Badges
Unanswered
log in
Ask
android
csv
I am new to Android. How can I run this For loop until the button is pressed? I am writing saved data of array into CSV file and storing it onto
SDcard. I want to keep the loop running until I press writeFileBtn and it saves the data into CSV.
@Override
public void onClick(View v) {
share
});
Muntazir Abbas
7 2
Asked
Dec 4 '15 at 16:16
Liuting
530 7 25
Edited
Dec 4 '15 at 16:49
short answer ... you need new Thread ... basically in run() of thread {while(running){ /*loop here*/} /* write file here*/ } ... then in on click of first button you starting
the thread ... and in second set running to false ... Selvin Dec 4 '15 at 16:19
of course it is just POC and have some caveats ... the real implementation should take to an account that activity can be closed ... or recreated ... so it would be
better to use fx service ..... etc. Selvin Dec 4 '15 at 16:25
add a comment
order by votes
1 Answer
}
AsynkTask provides you a isCancelled() that can be used by your button.
share
Answered
Dec 4 '15 at 16:29
The problem is I am really new to this coding. I have tried many solutions but not successful so far. Can somebody help me in modification my code already
mentioned above? Muntazir Abbas Dec 4 '15 at 16:33
you mean: writing the code for you, for free? why? josealfonsomora's example should be enough Selvin Dec 4 '15 at 16:36
add a comment
Your Answer
log in
or
Name
By posting your answer, you agree to the privacy policy and terms of service.
meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app