android - Stop asynctask from other activity -
i creating app using asynctask download file server. has several activities. start 1 asynctask activity , want stop activity b. how can archieve ???
it possible call previous activity's public methods using typecasting of getparentactivity() method on activity b :
((previousactivity)getparentactivity()).somepublicmethod();
this works if opened activity b activity a. if want able call method activities, try creating static class , save instance of activity a. way, wherever on app, method can called. wary of null values when doing this.
this sample of static class.
public static class constants{ public static activitya activityainstance; }
when open activitya (oncreate
method) save it's instance:
constants.activityainstance = activitya.this;
this part saves instance of activitya static class. whereever on app, can access instance , call it's public methods:
e.g. app on activityz have import static class , call activitya instance:
constants.activityainstance.somepublicmethodtostoptheasynctask();
Comments
Post a Comment