logo
down
shadow

does the context passed on getDefaultSharedPreferences affects the result?


does the context passed on getDefaultSharedPreferences affects the result?

By : Urill
Date : October 29 2020, 05:01 AM
may help you . It doesn't matter whether you provide an Application or an Activity as the Context parameter for PreferenceManager.getDefaultSharedPreferences().
If you look at the source for getDefaultSharedPreferences():
code :
return context.getSharedPreferences(getDefaultSharedPreferencesName(context),
        getDefaultSharedPreferencesMode());
return context.getPackageName() + "_preferences";


Share : facebook icon twitter icon
getDefaultSharedPreferences() - what is the context for a multi package application?

getDefaultSharedPreferences() - what is the context for a multi package application?


By : jon doe331
Date : March 29 2020, 07:55 AM
Any of those help Manifest Broadcast Receiver: The context in which the Manifest BroadcastReceiver runs is android.app.ReceiverRestrictedContext. This context has limited features enabled, though it does have packageName (that registered the receiver). Using getDefaultSharedPreferences in BroadcastReceiver should not be a problem as the information needed to retrieve the Default Shared Preferences (ie., package name) is available in this restricted context.
Dynamically Registered Broadcast Receivers: Dynamically registered Broadcast Receivers (registered using resgisterReceiver) run in the context of the Activity or the service that registered the receiver.
does it guarantee to give same result in getDefaultSharedPreferences within Context?

does it guarantee to give same result in getDefaultSharedPreferences within Context?


By : Ben Dincuta
Date : March 29 2020, 07:55 AM
This might help you I read this discussion but still have a question. , Wishing you a happy new year-2014
Both will behave same !!
code :
getDefaultSharedPreferences(context)
getSharedPreferences(context.getPackageName(), MODE_PRIVATE)
Context for getDefaultSharedPreferences() in database function file

Context for getDefaultSharedPreferences() in database function file


By : user7389671
Date : March 29 2020, 07:55 AM
this one helps. You'll need to pass the Context when instantiating the the Database class. Add a public constructor to the class Database:
code :
public class Database {

    private Context mContext;

    public Database(Context context) {
        mContext = context;
    }
}
What is context in PreferenceManager.getDefaultSharedPreferences used for?

What is context in PreferenceManager.getDefaultSharedPreferences used for?


By : Kevin Somervill
Date : March 29 2020, 07:55 AM
I hope this helps you . Given that any non-null context passed to PreferenceManager.getDefaultSharedPreferences will return the same result, what is context used for by PreferenceManager and what's the point of passing in different context? ,
what is context used for by PreferenceManager
cannot get right result from getdefaultsharedpreferences

cannot get right result from getdefaultsharedpreferences


By : leezng
Date : March 29 2020, 07:55 AM
should help you out you are using values as null for both keys mean there is only one key i.e. null which will override the each other (PREF_USERID_QUERY will over write previous values which were saved with null as key)
so give them values
code :
private static final String PREF_AUTHORIZED_QUERY = "authorized";

private static final String PREF_USERID_QUERY = "userid";
PreferenceManager.getDefaultSharedPreferences(context)
            .edit()
            .putString("null", authorizedHeader)
            .putString("null", userId) // so there is actually only one key 
            .apply();
Related Posts Related Posts :
  • Getting a string value from the strings.xml resource file and set it in an interface class
  • Flutter, sign with both debug keys and release keys on Android
  • will an android service run code from the Xamarin Forms Project even when the app is closed?
  • Change boolean values on listviewitems in firebase
  • Android Studio 3.2.1: mixing versions can lead to runtime crashes when connect firebase
  • FCM migration without losing the old token
  • Change reported Version Number in Fabric Crashlytics
  • lateinit property mMap has not been initialized
  • Android - PWA does not open in standalone mode with service worker
  • Does LeakCanary has callback?
  • How to disable back button after splash screen in React Native
  • Assets Folder Not Including HTML Files In NativeScript Android Build
  • Dagger: What if I *WANT* a new instance every time?
  • How to get mailto working on android chrome?
  • SSO web login in android app with customtabs
  • how to make specific button side curved
  • remove item onlongclick from listview
  • header image alignment coming wrongly in NavigationView android
  • How to add many spaces after the text in TextView
  • how to set "Back Button" , closing activies except main activity in android?
  • Unable to run emulator on Android Studio || Windows 10
  • How can I achieve this requirement using Rx Java
  • How to tilt a Node(or TransformableNode)object downwards in Sceneform(Ar Core)?
  • When to use RTL and LTR?
  • How to create a tab view (category) similar to instagram's explore tab
  • Glide, RecyclerView: Glide returns the same picture over and over again even with different data inputs
  • how to stop open activity while splash screen killed
  • Changing the Color of the Dynamically loaded Buttons onclick
  • Listview: Add arrows as dividers
  • Show confirmation on back/up in Fragment with Navigation Architecture Component
  • How to find the corresponding maven artifact/gradle module of an Android class from the API Docs?
  • ZXing 3.6.0 in portrait mode?
  • Can't use Subversion command line client: svn The path to the Subversion executable is probably wrong android
  • how to set spinner list value first position showing empty
  • When using PersistableBundle in onCreate, it shows me a blank page
  • Failed to resolve Bintray dependency
  • jacoco code coverage not working for Android applications
  • How to change the color of the Android scroll bumper
  • Why run Handler in main Looper thread
  • Android Studio combined chart crashes
  • Setting suggested width and height to a custom view in android
  • How to set input type and format in EditText using kotlin?
  • how to define Android Oncreate optionmenu
  • Exception on orientation change from two-pane mode to one-pane mode
  • How to access members of nested struct and assign them the values read from device tree?
  • How to measure upload progress of a huge String with Retrofit 2?
  • Runtime app localization doesn't work with app bundles
  • How create View and Putting TextView inside it in kotlin
  • how to integrate app action using actions.xml?
  • ConstraintLayout - center TextView in the root but don't override Button
  • Android Studio Text not conforming to layout_margin when I run App on Emulator
  • verifyReleaseResources apk release - react native
  • My app is not visible in share dialog even with intent filters in place
  • How to use cache or local storage?
  • Unhandled Exception in Recycler view xamarin
  • Android Workmanger PeriodicWorkRequest API work only once?
  • Using Touch ID or Face ID without storing user biometrics
  • React Native 3 button and 3 Modal
  • Token Expiration after 1 Hour in Authentication using Retrofit 2 and Logging Interceptor
  • JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException:
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org