Hi every one
I'm new in android
I'm trying to save a binary file with Asynctask and show process in a TextView
This is the layout:
<TextView
android:id="@+id/textView_pecent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And this is my java code:
private class hideit extends AsyncTask<String, Integer, Boolean> {
@Override
protected Boolean doInBackground(String... urls) {
try{
int c;
while((c = Data.read()) != -1) {
Data.write(c);
}
}catch (IOException e){
e.printStackTrace();
}
return true;
}
protected void onProgressUpdate(Integer... progress) {
textview.setText(INTEGER.toStirng(x)); //x =0
x++
}
protected void onPostExecute(Boolean result) {
Toast.makeText(getActivity(),"Done", Toast.LENGTH_LONG).show();
}
}
How do i use publish process?
I searched a lot but everyone use sleep or for or while loop but you can't do your process with sleep
I'm so confused how can i use this function to show my process in TextView
?
Should i call it many times?
Thanks
edit: This is an example:
protected String doInBackground(Integer... params) {
for (; count <= params[0]; count++) {
try {
Thread.sleep(1000);
publishProgress(count);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return "Task Completed.";
}
How can i add below code to the example
try{
int c;
while((c = Data.read()) != -1) {
Data.write(c);
}
}catch (IOException e){
e.printStackTrace();
}
return true;
}