I'm trying to implement simple app which shows ProgressBar updating. Following are my main tasks.
When app load first time and start ProgressBar uploading using AsyncTask it should display on UI (Done and working properly)
While updating ProgressBar, user exit from the app, uploading value should increment caz it is run on the AsyncTask (Done and working properly)
Next time app loading, ProgressBar should be start from the current updating progress value if there is still updating and running AsyncTasks (Issue)
Here is part of my code;
public class PUMainActivity extends Activity implements ProgUpAsync.MyThreadListener {
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pumain_activity);
progressBar = (ProgressBar) findViewById(R.id.pumainActivity_progressBar);
}
@Override
public void onTextViewChanging(final int progValue) {
runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar.setProgress(progValue);
}
});
}
}
Because of the listener I've implemented, I can get the current progress even second time when my app loads. But the ProgressBar UI is not updating. No compile/run time errors.
UPDATE with listener interface
Here is the implementation of listener
public class ProgUpAsync extends AsyncTask<Void, Integer, Void> {
private MyThreadListener mCallback;
public interface MyThreadListener {
public void onTextViewChanging(int progValue);
}
public ProgUpAsync(Activity paramActivity) {
try{
mCallback = (MyThreadListener) paramActivity;
}catch(ClassCastException e){
throw new ClassCastException(paramActivity.toString() + " must implement MyThreadListener");
}
}
@Override
protected Void doInBackground(Void... params) {
for(int i=0; i<=100; i++){
if((i%5) == 0){
publishProgress(i);
try {
Thread.sleep(5000);
} catch (InterruptedException ie) {
}
}
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
mCallback.onTextViewChanging(values[0]);
}
}