通过在一个活动中使用应用程序上下文,我已经将一些数据存储到全局类中。稍后,我必须在“片段”中检索这些值。我已经做了类似的事情来存储在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>
现在,当我尝试使用此方法获取应用程序上下文时...我没有获取上下文时...
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();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句