How to Control an Activity's Contents from a Service?
I am new to Android
Can anyone provide an example/help on this.
For example having a TextView's contents on an Activity automatically changed by a Service.
I already managed to get the service running, is there a listener I could use on the Activity class?
please please please pr开发者_JS百科ovide examples with answers
ZiGi
Have a look at Application class
class MyApplication extends Application {
private TextView textView;
public String getTextView(){
return textView;
}
public void setTextView(TextView textView){
this.textView = textView;
}
}
class MyActivity extends Activity {
@Override
public void onCreate(Bundle b){
...
MyApplication myApp = ((MyApplication)getApplicationContext());
TextView textview = myApp.getTextView();
...
}
}
Set global resources(that will be used in whole Application Context including Services) in above manner & you are done!
Have a look at the EarthQuakeViewer samples. http://www.wrox.com/WileyCDA/WroxTitle/Professional-Android-2-Application-Development.productCd-0470565527,descCd-DOWNLOAD.html
精彩评论