当前位置: 动力学知识库 > 问答 > 编程问答 >

android - I can not get any value from any class to IntentService

问题描述:

I am trying to pass the value to IntentService Class. But I can not get the value from any class.

I am following like this:

 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;

}

}

I am setting the value form HomePage like this.

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");

}

}

I am receiving the value like this:-

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());

}

}

But I am here getting null values. If i try to get the value in home page mean I can view the values. Please let me know why I can not get the value in IntentService?

分享给朋友:
您可能感兴趣的文章:
随机阅读: