Is it possible to start a new thread in an Async task? Something like that:
public class FirstActivity extends Activity { protected ProgressBar progBar; protected Intent intent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); progBar = (ProgressBar)findViewById(R.id.start_progressBar); progBar.setProgress(0); new StartingApp().execute(); } protected class StartingApp extends AsyncTask<Void, Integer, Void> { int myProgress; @Override protected void onPreExecute() { myProgress = 0; } @Override protected Void doInBackground(Void... params) { while(myProgress<50){ myProgress++; publishProgress(myProgress); SystemClock.sleep(10); } MyRunnableClass mrc = new MyRunnableClass(); mrc.run(); return null; } @Override protected void onPostExecute(Void result){ intent = new Intent(FirstActivity.this, SecondActivity.class); startActivity(intent); } @Override protected void onProgressUpdate(Integer... values) { progBar.setProgress(values[0]); } } }
MyRunnableClass is a class that implements Runnable. I want something like this, because in the first step I want to show a progress bar when the application is initialized (fill in data structures, initial threads).
One more question: should I use the run () or start () method?
Thanks in advance!
source share