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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -