我开发了一个Android应用程序,其中添加了备份选项。现在,我想添加在用户带有日期和时间的最后一次备份时提示用户的功能。如果他们没有做备份然后允许他们做备份。
请有人帮我解释如何执行此操作吗?
答案 0 :(得分:0)
假设您有备份功能:
public void backup(){
//get time of last backup
SharedPreferences sharedPref = context.getSharedPreferences(
"PrefsFile", Context.MODE_PRIVATE);
long time = System.currentTimeMillis();
long lastBackup = sharedPref.getLong("BackupTime", 0);
//if there was no previous backup, lastBackup will be 0
if (lastBackup != 0){
long timeDiff = time - lastBackup; //difference will be in milliseconds
//do what you need with the time difference
}
//code for backup
SharedPreferences.Editor editor = sharedPref.edit();
editor.putLong(getString("BackupTime), time); //update last backup time
editor.commit();
}