【发布时间】:2012-09-05 23:34:09
【问题描述】:
我正在尝试获取FragmentStackSupport Activity 的上下文并在内部静态类中使用它。
我已经在内部静态类中实例化了FragmentStackSupport,我正在使用getBaseContext() 来获取FragmentStackSupport 的上下文。
将外部类上下文放入GCMRegistar.checkDevice(thisContext) 不会在代码中产生错误,但会使应用程序崩溃。
我不能使用 'this' 或 FragmentStackSupport.this 因为内部类是静态的。如果课程是公开的,“这个”会起作用......
如何为checkDevice() 方法获取正确的上下文?
public class FragmentStackSupport extends SherlockFragmentActivity {
int mStackLevel = 1;
//...
public static class CountingFragment extends SherlockFragment implements OnClickListener{
//...
FragmentStackSupport FSSContext;
static CountingFragment newInstance(int num) {
CountingFragment f = new CountingFragment();
return f;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
FSSContext= new FragmentStackSupport();
FSSContext.getBaseContext();
Context thisContext;
//
// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(thisContext);
}
}
}
【问题讨论】:
-
将公共静态更改为私有无效。它产生了更多错误。
标签: android static google-cloud-messaging inner-classes android-context