Accessing Context on Android

I’m attempting to create a native android extension for accessing SharedPreferences, but have been unable to successfully access the Context to call the getSharedPreferences() method. I’ve tried scouring the forums and web for clues and/or information to locate this information, but had no luck.

The example from link below outlines how to access SharedPreferences like so:

Context context = getActivity();
SharedPreferences sharedPref = context.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);

Primarily an iOS and JS developer, my Android development experience is relatively limited. I’ve been able to implement the desired behavior for iOS and need to do the same for Android. Any assistance is greatly appreciated. Thank you in advance.

https://developer.android.com/training/basics/data-storage/shared-preferences.html

Hi iksnae,

You can try with com.fuse.Activity.getRootActivity() to access to the Context.

Regards,
Fernando

thank you so much Fernando! that’s just what I needed.