次の3つのクラスがあります。
WorkingThreadの実行中にprogressDialogを表示しようとすると、WorkingThreadが実行された後にのみProgressDialogが表示されます。私は何が間違っているのですか?
AsyncTaskの使用には興味がありません!
-StartActivity:
public class StartActivity extends Activity implements OnClickListener
{
public ProgressDialog pgd;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgv = (ImageView)findViewById(R.id.imageView1);
tv = (TextView)findViewById(R.id.textview);
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(this);
}
public void onClick(View v)
{
pgd = ProgressDialog.show(StartActivity.this, "", "Loading picture"); // Start ProgressDialog before starting activity
Intent ActivityIntent = new Intent(this, FirstActivity.class);
startActivityForResult(ActivityIntent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0 && resultCode == RESULT_OK)
{
pgd.dismiss(); //Stop ProgressDialog when FirstActivity is "done"
}
}
}
-
-FirstActivity:
public class FirstActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
WorkingThread wt = new WorkingThread();
wt.start();
try
{
wt.join();
Intent ActivityIntent = getIntent();
setResult(RESULT_OK, ActivityIntent);
finish();
}
catch (Exception e)
{
}
}
}
-WorkingThread:
public class WorkingThread extends Thread
{
@Override
public void run()
{
super.run();
try
{
Thread.sleep(5000);
}
catch (Exception e)
{
}
}
}