0

我正在开发一个 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");
    }
  }

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

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

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

七无

4

1 回答 1

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();
于 2012-11-29T08:31:50.330 回答