android - How can I call findViewById inside IntentService? -
is there way call findviewbyid
inside intentservice? in case, tried using static reference of mainactivity class. didn't work.
mainactivity class calls intentservice:
public static mainactivity ma; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); ma=this; startservice(new intent(this,myservice.class).setaction("myintent")); }
and myservice class is:
protected void onhandleintent(intent intent) { if(intent.getaction()=="myintent"){ listview lv=(listview)(mainactivity.ma.findviewbyid(r.id.listview)); toast.maketext(getapplicationcontext(), (mainactivity.ma.findviewbyid(r.id.listview)).tostring(), toast.length_long).show(); } }
this gives nullpointerexception. verified mainactivity.ma ok inside service class. still, cannot call findviewbyid
.
how can resolve this?
Comments
Post a Comment