I developed an application that receives content from the Internet and displays it accordingly on the device’s screen. The program works just fine, a little slower. Downloading and displaying content takes about 3-4 seconds. I would like to put all the code that extracts the content and displays it in the background thread, and while the program performs these functions, I would like to display a progress dialog. could you help me? I would especially like to know how to put code in a background thread.
MY CODE
public class Activity1 extends Activity { private ProgressDialog progressDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); new AsyncTask<Integer, Integer, Boolean>() { ProgressDialog progressDialog; @Override protected void onPreExecute() { progressDialog = ProgressDialog.show(Activity1.this, "", "Loading..."); } @Override protected Boolean doInBackground(Integer... params) { if (params == null) { return false; } try { Thread.sleep(params[0]);
source share