如何在使用SQLiteAssetHelper库时显示启动画面?

时间:2016-07-09 16:24:13

标签: android sqliteopenhelper

我将这个库SQLiteAssetHelper用于我预先创建的数据库。首次运行时,我的应用只显示白屏。我想图书馆正在将我的数据库(大约10秒)复制到适当的位置。并且启动画面仅显示在白色屏幕之后。我想在复制时显示闪屏。我该怎么做?

这是我的SplashActivity btw。

public class SplashActivity extends AppCompatActivity {

public static final String MyPREFERENCES = "MyPrefs" ;
public static final String COPIED = "copied";
SharedPreferences prefs;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    prefs = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);

    if (prefs.getBoolean(COPIED, true)) {
        new DatabaseCopier().execute(this);
        prefs.edit().putBoolean(COPIED, false).commit();
    } else {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                splashEnd();
            }
        }, 500);
    }

}

private void splashEnd() {
    Intent openListActivity = new Intent(this, MainListActivity.class);
    startActivity(openListActivity);
}

@Override
protected void onPause() {
    super.onPause();
    finish();
}

private class DatabaseCopier extends AsyncTask<Context, Void, Void> {
    @Override
    protected Void doInBackground(Context... params) {
        Log.i("suddenly here", "suddenly here 0");
        BookDatabaseHelper.getInstance(params[0]); //I thought it start copy from here but not
        DatabaseHelper.getInstance(params[0]);
        return null;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        splashEnd();
    }
}

}

0 个答案:

没有答案