我想在启动屏幕之间进行调整,首先在我的应用程序上显示 asynchtask,我从 splash 5 seconde 开始,然后是 asynchtask,我希望当我启动我的启动画面时 asynchtask 也开始加载,这是我的启动代码:
public class SplashActivity extends Activity {
private static String Spsc = SplashActivity.class.getName();
private static long time = 5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar
setContentView(R.layout.splash);
IntentLauncher launcher = new IntentLauncher();
launcher.start();
}
private class IntentLauncher extends Thread {
@Override
public void run() {
try {
Thread.sleep(time*1000);
} catch (Exception e) {
Log.e(Spsc, e.getMessage());
}
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
}
}
这是我从 mainActivity 的飞溅:
class FetchPosts extends AsyncTask<Void, Void, Void> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(MainActivity.this, "", getString(R.string.loading_message));
}
@Override
protected Void doInBackground(Void... params) {
articles = Services.getPosts(MainActivity.this);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
progressDialog.dismiss();
}
}