我正在尝试将值传递给IntentService类。但我无法从任何阶级中获得价值。
我这样跟着:
public class ModelClass {
private static ModelClass mInstance = null;
Activity mActivity;
String mString;
public static ModelClass getInstance() {
if (mInstance == null) {
mInstance = new ModelClass();
}
return mInstance;
}
public String getmString() {
return mString;
}
public void setmString(String mString) {
this.mString = mString;
}
public void setmActivity(Activity activity){
mActivity=activity;
}
public Activity getmActivity(){
return mActivity;
}
}
我正在设置类似HomePage的值。
public class Home extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ModelClass.getInstance().setmActivity(this);
ModelClass.getInstance().setmString("Testing String");
}
}
我收到的价值如下: -
public class BackgroundService extends IntentService {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
System.out.println("On Create==> ");
System.out.println("getmString() ==> "+ModelClass.getInstance().getmString());
System.out.println("getmActivity() ==> "+ModelClass.getInstance().getmActivity());
}
}
但我在这里获得空值。如果我试图获取主页中的值意味着我可以查看值。请告诉我为什么我无法在IntentService中获得价值?