【发布时间】:2011-12-28 09:52:24
【问题描述】:
目前我在做一个 android-phonegap 项目。
在应用加载 index.html 之前,有一些本地代码在工作。详细地说,它在 AsyncTask 中,它在 SD 卡(如果有的话)上四处走动。
我设法在 A.Task 工作时显示了一个进度条,但我还想在后台添加一个启动画面。我主要使用 Phonegap 并从本机代码开始。因此,我对所有这些布局、主题以及您可能在 .xml 文件中定义的其他内容感到有些困惑。我很确定这对于更大的 UI 设计也是一个好主意,但对于我现在想要的简单启动画面来说,这感觉有点过头了。
这是一个来自源的 sn-p。直接向前。 onCreate() 调用 AsyncTask 完成一些工作并在其 PostExecute 方法中启动 PhoneGap。我希望屏幕出现在 onCreate 方法或 onPreExecute 中。工作完成后,我会在 onPostExecute() 中关闭屏幕。我还添加了 cmets 来说明我的想法。
public class myAct extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Show Splash here or in onPreExecute()!
new myAsTa().execute();
}
}
class myAsTa extends AsyncTask<Void, Integer, Boolean> {
ProgressDialog dialog = new ProgressDialog(myAct.this);
@Override
protected void onPreExecute() {
//or show splash here!
dialog.setMessage("Cool Progressbar!");
dialog.show();
super.onPreExecute();
}
protected Boolean doInBackground(Void... values) {
//magician at work!
return true;
}
@Override
protected void onProgressUpdate(Integer... values) {
//insult user here
}
protected void onPostExecute(Boolean result) {
dialog.dismiss();
//dismiss splashscreen
//start Phonegap
}
}
感谢您的阅读和帮助:)
【问题讨论】:
标签: android splash-screen