android - How to use Context to access/manipulate another class/activity -
i want create generic asyncetask class activities use/share downloading content url. reason, don't want onpostexecute other send content method in activity invoked asynctask class.
i know need create constructor sets context of activity invoked asynctask
, what, how use context send the activity corresponding context. i've seen no tutorials show how use context in manner.
lets have:
public class loginactivity { public int activitymember; public void handlebuttonclick(void){ downloadfromurl task = new downloadfromurl(this); task.execute(url); } public void handleloginresult(int x){ activitymember = x; } }
now in separate java file have:
private class downloadfromurl extends asynctask<list<namevaluepair>, long, jsonobject> { context context; public void downloadfromurl (context context){ this.context = context; } @override protected void onpostexecute(jsonobject json) { context.(<- *my question involves part of code) } }
i'm pretty sure cant call context.activitymember
, or context.handleloginresult(y)
inside onpostexecute
, because context not of type loginactivity
, context. how can access members or methods belonging loginactivity
, using it's context?
you can use ((activityname)contextname).methodname()
but not solution. can try this
Comments
Post a Comment