我已通过在一个活动中使用应用程序上下文将一些数据存储到全局类中。稍后我必须在片段中检索这些值。我已经做了类似的事情来存储在全局类中。
AndroidGlobalClass AGC = ((AndroidGlobalClass) getApplicationContext());
AGC.setUser_access("XYZ");
AGC.setFirst_name("ABC");
在清单中我已经做了:
<application
android:name=".AndroidGlobalClass"
android:theme="@style/AppTheme" >
<activity
android:name="abc.SignInActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
现在,当我尝试使用此获取应用程序上下文时...我没有获取上下文...
AndroidGlobalClass AGC = ((AndroidGlobalClass) getApplicationContext());
这是我的片段活动
public class Fragment_NewsFeed extends Fragment {
public Fragment_NewsFeed() {
}
RestImplimentationMethods RIM;
AndroidGlobalClass AGC;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_newsfeed, container, false);
return rootView;
}
}
您可以使用获取上下文getActivity().getApplicationContext();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)