I am trying to restore the bike_info.db to my application the db file has some records and I want to restore them in the app
I tried with below code, toast successful is displayed but db is not getting restored, I don't know why. can anyone help?
rest = (Button) findViewById(R.id.cview_restore);
rest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "com.infyco.kp.new_tab"
+ "//databases//" + "bike_info.db";
String backupDBPath = "//data//bike_info.db"; // From SD directory.
File backupDB = new File(data, currentDBPath);
File currentDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(backupDB).getChannel();
FileChannel dst = new FileOutputStream(currentDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Import Successful!",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Import Failed!", Toast.LENGTH_SHORT)
.show();
}
}
});
after clicking on rest button this is the output from android monitor:
01-17 14:00:40.922 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: ViewPostImeInputStage processPointer 0
01-17 14:00:40.962 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: ViewPostImeInputStage processPointer 1
01-17 14:00:41.012 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: #1 mView = android.widget.LinearLayout{9ba3ae9 V.E...... ......I. 0,0-0,0 #102039d android:id/toast_layout_root}
01-17 14:00:41.072 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
01-17 14:00:43.022 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: #3 mView = null