@Override public boolean restore(Context context, Object data, IAsyncTaskListener listener) { if (context == null || data == null || listener == null) { return false; } if (!(data instanceof RestoreArgs)) { return false; } // if(!(context instanceof Activity)){ // return false; // } mRestoreContext = context.getApplicationContext(); mListener = listener; mArgs = (RestoreArgs) data; setState(RestoreState.RESTORING); mListener.onStart(GoLauncherSettingRestoreEntry.this, null); // 根据需求,如果在备份时数据库不存在,在恢复时,则不需恢复,直接是恢复成功 if (mDBNotExitWhenBackup || mRandomStr == null) { mListener.onEnd(true, GoLauncherSettingRestoreEntry.this, null); } else { if (mRestoreContext != null && mReceive != null) { try { mRestoreContext.unregisterReceiver(mReceive); } catch (Exception e) { e.printStackTrace(); } mReceive = null; } mReceive = new RestoreGoLauncherReceive(); try { mRestoreContext.registerReceiver(mReceive, mReceive.getIntentFilter()); } catch (Exception e) { e.printStackTrace(); } Intent it = new Intent(); it.setAction(ACTION_BACKUP_RESTORE_GOLAUNCHER); it.putExtra(BACKPATH, mArgs.mRestorePath); if (mDBNotExitWhenBackup) { it.putExtra(BACKCMD, DATABASE_NOT_EXIT); } else { it.putExtra(BACKCMD, CMD_RESTOREDB); } it.putExtra(RANDOMSTR, mRandomStr); context.sendBroadcast(it); startTimer(); } return true; }
private void finishRestore(Intent intent) { if (mTimer != null) { mTimer.cancel(); } boolean ret = false; if (intent != null) { String result = intent.getStringExtra(BACKINFO); Log.d("test", "finishBackup : result = " + result); if (result != null) { if (result.equals(DFILE_IMPORT_ERROR) || result.equals(SDCARD_UNMOUNTED) || result.equals(DBFILE_NOT_FOUND)) { ret = false; } else if (result.equals(DFILE_IMPORT_SUCCESS)) { ret = true; } } } else { ret = false; } // 设置恢复状态 RestoreState state = ret ? RestoreState.RESTORE_SUCCESSFUL : RestoreState.RESTORE_ERROR_OCCURRED; setState(state); if (mListener != null) { mListener.onEnd(ret, GoLauncherSettingRestoreEntry.this, null); } if (mRestoreContext != null && mReceive != null) { try { mRestoreContext.unregisterReceiver(mReceive); } catch (Exception e) { e.printStackTrace(); } mReceive = null; } mRestoreContext = null; mListener = null; mArgs = null; mTimer = null; mTimerTask = null; }