, 여기에 내가 무엇을 그리고 찾다 오류 :응용 프로그램 컨텍스트 단검 사용?
@Module(injects = { MyApp.class, TransportModule.class }, library = true, includes = { TransportModule.class })
public class AppModule {
private final MyApp remoteApp;
public AppModule(MyApp remoteApp) {
this.remoteApp = remoteApp;
}
@Provides
@Singleton
Context provideApplicationContext() {
return remoteApp;
}
}
응용 프로그램 클래스 :
@Override
public void onCreate() {
instance = this;
super.onCreate();
objectGraph = ObjectGraph.create(getModules().toArray());
objectGraph.inject(this);
mContext = getApplicationContext();
private List<Object> getModules() {
return Arrays.<Object>asList(new AppModule(this));
}
public ObjectGraph createScopedGraph(Object... modules) {
return objectGraph.plus(modules);
}
public static Context getContext() {
return mContext;
}
public static LoQooApp getInstance() {
return instance;
}
}
DeviceInfo.java를 :
public class DeviceInfo {
static LoQooApp baseApp;
@Inject
static Context mContext;
public DeviceInfo() {
}
public static boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(mContext);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
Log.v(TAG, Integer.toString(resultCode));
} else {
Log.i(TAG + "NOPE", "This device is not supported.");
}
return false;
}
return true;
}
}
로그 캣 오류 :
DeviceInfo에는 컨텍스트가 모두 필요한 메서드가 많이 있습니다. 모두 실패합니다. 대거를 통해 또는 단검없이 컨텍스트를 가져 오는 방법은 무엇입니까?
정적 참조를 '컨텍스트'에 보관하고 싶지는 않습니다. 메소드의 매개 변수로 제공하거나 생성자에서'Context'를 취하는'DeviceInfo' 인스턴스를 생성하십시오. 그런 다음 그것을 사용하여 클래스에'DeviceInfo' 인스턴스를 삽입 할 수 있습니다. – nhaarman
DeviceInfo를 어디에 삽입합니까? BaseActivity와 같은 메소드를 사용하는 다른 클래스는 무엇입니까? – sirvon