Activity with ProgressBar -> Service -> AsyncTask for downloading - but how to update the progress?

后端 未结 3 993
小蘑菇
小蘑菇 2021-02-03 16:32

this is the current state/situation: I have an Activity which binds a Service which creates AsyncTasks which downloads various web resources. That works well, but of course the

3条回答
  •  后悔当初
    2021-02-03 16:57

    You can show progress just as easily via a Toast, which obviates all of the UI concerns:

    public class foo extends Service {
    private Toast toast;
    
    @SuppressLint("ShowToast")
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);
        ctxt = getApplicationContext();
        toast = Toast.makeText(ctxt, "", Toast.LENGTH_SHORT);
        ...
    }
    
    public void functionCalledByYourAsyncWithUpdates(String progress){
        toast.setText (progress);
        toast.show;
    }
    }
    

提交回复
热议问题