我的应用程序在启动时加载了很多东西,经过测试,它在开始时延迟太久而没有splash screen
. 所以,我想显示一个splash screen
直到我的应用程序完成加载。我不想在 X 秒内显示带有计时器的屏幕。我在这里找到了一个例子:
我尝试在上面的 SO 主题中实现代码,但我只是不理解代码。将它集成到我的代码中后,我发现了一个错误,我在下面的代码中进行了注释。但是我不懂很多代码,我在下面的代码中评论了我感到困惑的部分。
public class MainMenu extends Activity {
private ProgressDialog pd = null;
private Object data = null; //What is this?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mainmenu);
// show the ProgressDialog on this thread
this.pd = ProgressDialog.show(this, "Working...", "Downloading data...", true, false);
// start a new thread that will download all the data
new DownloadTask().execute("Any parameters to download."); //What is DownloadTask()?
}
private class DownloadTask extends AsyncTask<String, Void, Object> {
protected Object doInBackground(String... args) { //Are these parameters correct?
return "replace this with your object"; //What is this?
}
protected void onPostExecute(Object results) {
// pass the resulting data to the main activity
MainMenu.this.data = result; //Error: "result cannot be resolved to a variable"
if(MainMenu.this.pd != null) {
MainMenu.this.pd.dismiss();
}
}
}
}