获取应用程序上下文在片段的Android? [英] Get the Application Context In Fragment In Android?
本文介绍了获取应用程序上下文在片段的Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经存储了一些数据,以全局类通过使用应用程序上下文在一个活动。后来我要检索片段这些值。我做了这样的事情存储在全局类。
I have stored some data to a Global Class By using the Application Context In One Activity. Later I have to Retrieve those values in A Fragment. I have done something like this to store in Global Class.
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>
现在当我试图让应用程序环境使用这个......我没有收到背景下...
Now When I am Trying to Get the Application Context Using this... I am not getting the Context...
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;
}
}
需要帮助的ASAP。
Need Help ASAP.
推荐答案
您可以通过获取上下文
getActivity()getApplicationContext();
You can get the context using
getActivity().getApplicationContext();
这篇关于获取应用程序上下文在片段的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文