Context baseContext = getActivity().getBaseContext(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(baseContext); String username = prefs.getString("username", "");
Context baseContext = getBaseContext(); Intent intent = new Intent(baseContext, SettingsActivity.class); startActivity(intent);In this example, the base context is used to start a settings activity. Package library: android.content