java - Android calling class functions from second class -
how can call function defined in class#a class#b?
class#b extends aynchtask , fetches remote data web service. class#a function attempting call class#b used send retrieved remote data class#a display.
i trying pass current instance of class#a class#b using this passes context functions not recognized.
i tried using static function runs new thread, defining function static generates compiler error.
the code trying call follows:
public void test(list<data> data){ this.data = data; runonuithread(new runnable() { @override public void run() { // todo auto-generated method stub for(data data : mainactivity.this.data){ toast.maketext(mainactivity.this, data.title, toast.length_short).show(); } } }); } can me this?
this how it:
in mainactivity:
classbasynctask mat = new classbasynctask(this, .., ..); classbasynctask's contructor:
public classbasynctask(mainactivity context, .., ..) { mcontext = context; .... .... } to call mainactivity's method test(list<data>) within classbasynctask:
((mainactivity)mcontext).test(yourlistvariable); look weak references make sure asynctask not use mcontext when activity no longer exists.
Comments
Post a Comment