我正在学习如何使用Roboguice,而且我很难理解如何注入系统服务。我见过的所有例子都是注入一个活动,但我想将它注入POJO。我正在使用Roboguice 2.0 beta 3Roboguice注射系统服务
我有一个PhoneNumber类,并且希望注入TelephonyManager服务。
public class PhoneNumber {
@Inject TelephonyManager mTelephonyManager;
protected Integer getNetworkCountryPrefix() {
// This gives a null pointer exception
mTelephonyManager.getNetworkCountryIso();
}
}
当注入扩展RoboActivity的类时,一切正常。但是是否可以在不扩展RoboActivity的类中注入TelephonyManager?
谢谢,这清理了很多。 – 2011-12-20 22:32:44