I cannot figure out for the life of me what the getActivity method does.
I'm relatively new to programming android and I'm trying to give my app it's own small amount of storage. To do that I'm using SharedPreferences. Usually I wouldn't be copying "word for word" what's on Android Developers but, I am about to give up hope because I can't get anything to work. I can't even get the code from the website to work correctly
Here is the relevant code I have in my app.
public String activeTab = "course_reg";
private static final String DEBUG_TAG = "Gestures";
public static final String MY_PREFS_NAME = "MyPrefsFile";
Context context = getActivity();
SharedPreferences sharedPref = context.getSharedPreferences(
MY_PREFS_NAME, Context.MODE_PRIVATE);
The code from Android Developers is below.
Context context = getActivity();
SharedPreferences sharedPref = context.getSharedPreferences(
getString(R.string.preference_file_key), Context.MODE_PRIVATE);
Here is the website Android Developer page: Save key-value data
Every time I put getActivity() into Android Studio it says that it cannot resolve the method.
I don't know what I'm supposed to do with it and every other question I've gone to on Stack Overflow doesn't end up telling me anything.
What does getActivity do and/or what am I doing wrong.