SharedPreferences Android


        	
        	  SharedPreferences sp_name = this.getSharedPreferences("number", Context.MODE_WORLD_READABLE);
    		  boolean flag = sp_name.edit().putInt("num", 3).commit();
    		  if(true == flag)
    			  Toast.makeText(this, "write the value into sharedpreferences successfully", Toast.LENGTH_LONG).show();
        	 
        	  
        	 SharedPreferences sp = this.getSharedPreferences("number", Context.MODE_WORLD_WRITEABLE);
        	 int number = sp.getInt("num", 0);
        	 Toast.makeText(this, "the number is:"+number, Toast.LENGTH_LONG).show();
        	 boolean flag_delete = sp.edit().remove("num").commit();
        	 if(true == flag_delete)
        		 Toast.makeText(this, "delete the key-value successfully", Toast.LENGTH_LONG).show();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章