Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8986069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:27:49+00:00 2026-06-15T21:27:49+00:00

Today I encountered a really strange problem in Android. I am using 2 fields

  • 0

Today I encountered a really strange problem in Android.
I am using 2 fields with shared preferences. One is deviceId and second is Hashkey.
Now first I store only deviceId in sharedprefs, using code

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);

then I read hashKey from shared preferences and assign it to a variable in my global application class

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);
    }

But problem is when I run this code for first time, the value of hasKey in shared preferences is same as value of deviceID(running on emulator) i.e.

000000000000000

So I first uninstalled the application and then deleted and re created a new emulator, but every time the value of hashkey in shared preferences is same and it is 000000000000000. So how is it possible, because I think, I haven’t write the value in shared preferences so it should be null or something else, but definitely not 000000000000000

The output on Log cat is

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

And code of my SharedPref class is

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();
}
}

So why is it happening ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:27:50+00:00Added an answer on June 15, 2026 at 9:27 pm

    In your class SharedPref, you defined constants DEVICE_ID and KEY_HASH as both equal to “”.
    So I guess they refer to the same field in your Shared Preferences. Although it seems weird than an empty field can exists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I encountered a strange problem today. Whenever i put a breakpoint in one of
Today, I've encountered a strange problem with Groovy code that is run from Maven
I encountered a strange problem today. The good: I successfully changed a global var
Today I encountered something strange: I tried to put a utility method into an
Encountered a frustrating problem in our application today which came down to an ArrayIndexOutOfBounds
I have encountered this problem today and I don't have an explanation for it.
today i hit a really annoing problem with wpf. i just want to align
I have encountered a very strange thing today : I have an app installed
I've encountered an extreme weird problem on Android device where the data in listview
Today I encountered a pecularity which, although probably not really important, nevertheless puzzles me.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.