我想使用AsyncTask来创建启动画面。具体来说,在doInBackground()方法中,我使用静态方法Thread.sleep()并在它创建后将应用程序重定向到其他活动。我没有收到任何错误,但该应用没有改变活动。我的代码是:使用AsyncTask进行睡眠
/***This class redirects the user to the 'MainActivity'. ***/
class RedirectToMainActivityTask extends AsyncTask<Void, Void, Void>
{
protected Void doInBackground(Void... params)
{
try
{
Thread.sleep(2 * 1000);
}
catch (InterruptedException e)
{
Log.e("MAINACTIVITY-ERROR", e.getMessage());
showTheError("Error while starting MainActivity: " + e.getMessage());
}
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
return null;
}
}
哎,如果我的回答帮你出,请注明它至于:) –