Phonegap:Android上有两个页面重叠

时间:2012-11-29 07:17:22

标签: android cordova

我正在开发Android / Phonegap应用。以下是我的代码:

public class SharePointProjectActivity extends DroidGap {
  /* SharedPreferences are used so that any initial setup can be done, 
     * i.e operations that are done once in life-time of an application
     * such as coping of database file to required location, initial wait 
     * request page,etc.
  */
  private SharedPreferences myPreferences;
  private Boolean registration;
  private static final String PREFS_NAME = "Register";
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    myPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    registration = myPreferences.getBoolean(PREFS_NAME, false);
    if (!registration) {
    //this code would load index1.html which would just display "Initialization is going on please wait"
      super.loadUrl("file:///android_asset/www/index1.html");
      try {
        //some code to copy the database files
      }
      catch (IOException e) {
        //some exception during the operation
      }
      //once the database file are copied i want to load the login page.Remember this would happen during installation only, successive runs (launch) would directly load the login page i.e index2.html
      super.loadUrl("file:///android_asset/www/index2.html");
      SharedPreferences.Editor editor = myPreferences.edit();
      editor.putBoolean(PREFS_NAME, true);
      editor.commit();
    } else {
      super.loadUrl("file:///android_asset/www/index.html");
    }
  }

问题:在安装过程中,两个页面都被加载到另一个页面上,即index1..html上的index2.html。

预期:在复制过程中,index1.html应该显示,一旦完成,index1.html应该消失,index2.html应该加载。

编辑:我将在安装过程中使用两个html文件,第一个文件将只显示一个图像,要求用户在安装过程中等待,如果一切正常,则应加载登录页面(第二个文件)。到目前为止,这是有效的,但当我点击后退按钮控制转到第一页。 提前谢谢,

Nanashi

1 个答案:

答案 0 :(得分:1)

您可以尝试使用AsyncTask,如果您使用它,它将允许用户与您的应用进行交互,因为您不会使用UI线程

public class LoadDataTask extends AsyncTask<Void, Void, Void> {
      protected void onPreExecute() {
            SharePointProjectActivity.this.super.loadUrl("file:///android_asset/www/index1.html");
      }

      protected void doInBackground(final Void... args) {
         ... do you db stuff ...
         return null;
      }

      @Override
      protected void onPostExecute(Void result) {
           SharePointProjectActivity.this.super.loadUrl("file:///android_asset/www/index2.html");
      }
   }

你可以通过

开始一个asynctask
new LoadDataTast().execute();