2017-03-20 42 views
-3

我得到這個作爲我的服務器response.And我想存儲所有設備,以便用戶的會話必須創建並存儲在設備上,以便進一步登錄到應用程序不需要。如果用戶註銷應用程序,則該數據必須被刪除。 我卡在這裏....請告訴我一種方法來解決這個問題。保存服務器響應本地在Android設備

03-20 13:18:56.486 20338-20537/? D/Null: Params :{data[User][password]=pfrt1fKLkoZhAT6hoMJFiA== 
             , data[User][email]=RyUMRBg7UyeIlFBBtNemZFuG46PJtAIdiZWXnlJ4zNI= 
             } 
03-20 13:18:56.609 20338-20338/? D/Null: Reponse Check :{"code":200,"user":{"User":{"id":"ui1bJkK19jxbaquTboA2oQ==","email":"RyUMRBg7UyeIlFBBtNemZFuG46PJtAIdiZWXnlJ4zNI=","status":"1","verified":"1","created":"2016-03-07 11:41:59","modified":"2016-04-07 15:43:43","token":"6b987332b77d7c69d76bf7be80a85177fb7fa08d"},"Profile":{"id":"1","first_name":"Pradeep","last_name":"Gupta","bio":"sfafaf","address":"82, Debinibash Road\r\nDum Dum, P.O. - Motijheel","phone":"+913325505055","profile_pic":"\/img\/356a192b7913b04c54574d18c28d46e6395428ab\/license.jpg","user_id":"1","Contributor":{"id":"31","profile_id":"1","status":"1","vs_cdn_id":"261961777","secret_token":"s-7Va5z","uploaded_on":null,"statement":"AOK KJDHKJDH bkgkg kkhkjh kjhkj kjh kjhkjh","time":"7 hours per month","created":"2016-05-02 18:40:11","modified":"2016-05-02 18:41:29"},"Moderator":[]},"redirect":"\/"}} 
03-20 13:18:56.695 20338-20338/? D/Null: Object Check :ModelObject{code='200', id='null', email='null', first_name='null', last_name='null'} 
03-20 13:18:56.695 20338-20338/? D/Null: Object Check :class com.example.user.myapplication.ModelObject 
+0

根據要存儲的數據量使用「Realm」或「SharedPreferences」 –

回答

0

你可以通過使用SharedPreferences來解決這個問題。

保存數據:

SharedPreferences preferences = context.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE); 
SharedPreferences.Editor data = preferences.edit(); 
data.putString("loginInfo", yourLoginObjectString); 
data.commit(); 

讀取數據:

String loginObjectString = preferences.getString("loginInfo", "defaultValue"); 
0

您可以從例如響應考慮任何獨特的領域電子郵件或ID,或這將是對於每個用戶不同,並且它(本地設備存儲)保存SharedPreferences以下面的方式命名..

在偏好設定值:

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit(); 
editor.putString("name", "Pradeep"); 
editor.putInt("idName", 12); 
editor.commit(); 

檢索來自數據喜好:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String restoredText = prefs.getString("text", null); 
if (restoredText != null) { 
    String name = prefs.getString("name", "No name defined");//"No name defined" is the default value. 
    int idName = prefs.getInt("idName", 0); //0 is the default value. 
} 

當用戶退出應用程序的,設置字段設置爲null。 每次啓動應用程序檢查保存的字段是否存在(空檢查)。 就是這樣。

相關問題