1、怎么样才能实现这个效果那,就是把 raw 里的压缩文件,解压缩成数据库文件,然后放入项目里,这需要,一些时间,所以,我用了一个 ProgressDialog 来增加用户体验,也防止 kill Activity ,首先看启 ProgressDialog 然后再开启线程,当线程执行完成之后发送消息sendmessage,handler 接受到 msg.what 相匹配的消息之后,处理时间,把 Dialog dismiss掉.下面这个教程比较简单。java 代码:Overridepublic void onCreate(Bundle savedInstanceState) super.onCreat
2、e(savedInstanceState);setContentView(R.layout.main);button = (Button) findViewById(R.id.button);et = (EditText) findViewById(R.id.edittext);tv = (TextView) findViewById(R.id.textview);initProgressDialog();Log.d(TAG, ”thread run”);/在 onCreate 方法里开启线程new Thread()public void run() / TODO Auto-generated
3、 method stubLog.d(TAG, ”run start”);dbhelper = new DBManager(AttrActivity.this);/执行我需要进行的导入数据库的操作dbhelper.openDatabase();/dbhelper.closeDatabase();/ handler.sendEmptyMessage(1);Message msg = new Message();msg.arg1 = 100; /message.arg1 携带 100msg.arg2 = 200; /message.arg2 携带 200msg.what = 1;handler.se
4、ndMessage(msg); /发送 msg 消息.start();/handler 为处理消息Handler handler = new Handler()Overridepublic void handleMessage(Message msg) / TODO Auto-generated method stubsuper.handleMessage(msg);if(msg.what = 1)/handler 通过 msg.what 判断线程发给他的 msg 如果符合,执行 msg.what 对应操作,当然msg 携带的变量也可以取出Log.d(TAG, ”msg.arg1 = ” +
5、msg.arg1);Log.d(TAG, ”msg.arg2 = ” + msg.arg2);mProgressDialog.dismiss();button.setOnClickListener(this);sqldb = SQLiteDatabase.openOrCreateDatabase(DBManager.DB_PATH + ”/” + DBManager.DB_NAME, null);public void initProgressDialog()mProgressDialog = new ProgressDialog(AttrActivity.this);mProgressDialog.setTitle(“”);mProgressDialog.setMessage(“aaa”);/ mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);mProgressDialog.show();