android 历史记录的存储读写

有时候常常进行一些不连续的重复的操做.这就须要用到历史记录来快速的进行操做了.
关于历史记录的存储读写,我写了个小方法.以下:
point 是起指向做用,指向最旧的记录.好比有N条记录(最多),1~N,写入一条记录后point=(point+1)%N;读取时最新的记录在前面.
this

下面是存储路径的历史记录的实现方法: spa

List<String> readHistory(){ get


        List<String> list= new ArrayList< String>();
        Context ctx =this; 
        SharedPreferences SAVE = ctx.getSharedPreferences("save", MODE_PRIVATE);
         int point=SAVE.getInt("point", 0);
        String path;
       
final int N=16;
         for(int i=0,n=point;i<=N;i++){
              path=SAVE.getString("path"+n, null);
              if(path!=null){
             list.add(path);
             }
it

            n=n>0?(--n):(--n+N)%16;
         } 
      
            return list;
    }
 
List

     void writeHistory(String path){
     Context ctx = this;
    SharedPreferences SAVE = ctx.getSharedPreferences("save", MODE_PRIVATE);
    int n=SAVE.getInt("point", 0);
    Editor editor = SAVE.edit();
    editor.putString("path"+n, path);
    editor.putInt("point",( n+1)%16);
    editor.commit(); 
     }


最后用列表列出来便可. 方法

相关文章
相关标签/搜索