0

오늘 Android에서 정말 이상한 문제가 발생했습니다. 공유 환경 설정으로 2 개의 필드를 사용하고 있습니다. 하나는 deviceId이고 두 번째는 Hashkey입니다. 지금 처음 나는공유 환경 설정의 필드 기본값은 무엇입니까?

new SharedPref(Home.this); 
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
    String deviceId = telephonyManager.getDeviceId(); 

    MyApplicationGlobal.DEVICE_ID = deviceId; 
    Log.v("deviceId in getAndStoreDeviceId()", "deviceId: " + deviceId); 
    SharedPref.writeString(SharedPref.DEVICE_ID, deviceId); 

그때 내가 공유 환경 설정에서 hashKey를 읽고 내 전역 응용 프로그램 클래스의 변수에

if (MyApplicationGlobal.HASHKEY == null) { 
     Log.v("in setHashKey before", "MyApplicationGlobal.HASHKEY: " + MyApplicationGlobal.HASHKEY); 
     MyApplicationGlobal.HASHKEY = SharedPref.readString(SharedPref.KEY_HASH, null); 
     Log.v("in setHashKey after", "MyApplicationGlobal.HASHKEY: " + MyApplicationGlobal.HASHKEY); 
    } 

를 할당하지만 실행할 때 문제가 코드를 사용하여, sharedprefs 만의 DeviceID를 저장 처음으로이 코드는 공유 환경 설정에서 hasKey의 값의 DeviceID 즉

000000000000000 

그래서 처음 UNINST (에뮬레이터에서 실행)의 값과 동일 모든 응용 프로그램을 삭제 한 다음 새 에뮬레이터를 삭제하고 다시 만들었지 만 공유 환경 설정의 hashkey 값이 같을 때마다 000000000000000이됩니다. 공유 환경 설정에 값을 쓰지 않은 이유는 무엇일까? 그래서 확실히 null 또는 뭔가 다른,하지만이되어야하지 000000000000000

로그 고양이 출력은

12-14 19:55:21.733: V/deviceId in getAndStoreDeviceId()(969): deviceId: 000000000000000 
12-14 19:55:21.753: V/in setHashKey before(969): MyApplicationGlobal.HASHKEY: null 
12-14 19:55:21.753: V/in setHashKey after(969): MyApplicationGlobal.HASHKEY:  000000000000000 
12-14 19:55:21.765: V/in UserFunctions() MyApplicationGlobal.Hask_KEY(969): MyApplicationGlobal.HASH_KEY: 000000000000000 
12-14 19:55:21.813: V/in getListOfEventCountries() MyApplicationGlobal.HASH_KEY(969): MyApplicationGlobal.HASH_KEY: 000000000000000 

그리고 내 SharedPref 클래스의 코드 그래서 왜 일어나고

package com.library.shared_preference; 

import android.content.Context; 
import android.content.SharedPreferences; 
import android.content.SharedPreferences.Editor; 

public class SharedPref { 
public static final String PREF_NAME = "SHARED_PREFERENCES_FOR_TRACKINT"; 
public static final String SEARCHED_IMG_URL = "SEARCHED_IMG_URL"; 
public static final String SEARCHED_IMG_NAME = "SEARCHED_IMG_NAME"; 
public static final String SEARCHED_IMG_ACTUAL_PRICE = "SEARCHED_IMG_ACTUAL_PRICE"; 
public static final String UID_RES = "u_id"; 
public static final String USER_EMAIL = "user_name"; 
public static final String USER_PWD = "user_pwd"; 

public static final String FB_UID_RES = "u_id"; 
public static final String FB_USER_EMAIL = "user_name"; 
public static final String FB_USER_PWD = "user_pwd"; 
public static final String DEVICE_ID = ""; 
public static final String KEY_HASH = ""; 

static Context _context; 

// constructor 
public SharedPref(Context c) { 
    _context = c; 
} 

// for boolean value 
public static void writeBoolean(String key, boolean value) { 
    getEditor().putBoolean(key, value).commit(); 
} 

public static boolean readBoolean(String key, boolean defValue) { 
    return getPreferences().getBoolean(key, defValue); 
} 

// for integer value 
public static void writeInteger(String key, int value) { 
    getEditor().putInt(key, value).commit(); 

} 

public static int readInteger(String key, int defValue) { 
    return getPreferences().getInt(key, defValue); 
} 

// for String value 
public static void writeString(String key, String value) { 
    getEditor().putString(key, value).commit(); 

} 

public static String readString(String key, String defValue) { 
    return getPreferences().getString(key, defValue); 
} 

// for float value 
public static void writeFloat(String key, float value) { 
    getEditor().putFloat(key, value).commit(); 
} 

public static float readFloat(String key, float defValue) { 
    return getPreferences().getFloat(key, defValue); 
} 

// for long value 
public static void writeLong(String key, long value) { 
    getEditor().putLong(key, value).commit(); 
} 

public static long readLong(String key, long defValue) { 
    return getPreferences().getLong(key, defValue); 
} 

@SuppressWarnings("static-access") 
public static SharedPreferences getPreferences() { 
    return _context.getSharedPreferences(PREF_NAME, _context.MODE_PRIVATE); 
} 

public static Editor getEditor() { 
    return getPreferences().edit(); 
} 
} 

이다?

답변

1

SharedPref에서 상수 DEVICE_ID와 KEY_HASH를 둘 다 ""로 정의했습니다. 공유 환경 설정에서 같은 필드를 참조하는 것 같습니다. 그것은 빈 필드보다 이상한 것 같습니다.

관련 문제