java - How do I execute a class in another activity -


i'm trying execute class(getdirecoes, in mapsactivity) activity (detailsactivity), idea is, when click in floating action button (detailsactivity) execute class (getdirecoes) , close current activity (detailsactivity), when close activity automatically open parent activity (mapsactivity) method getdirecoes is. i'm trying execute method this:

new mapsactivity.getdirecoes().execute(latrepr, lngrepr); 

but doesn't work giving me error:

mapsactivity' not enclosing class

the correction android studio offers me make getdirecoes static, can't because if entire class breaks, here's getdirecoes class:

public class getdirecoes extends asynctask<string, void, void> implements serializable {          @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(mapsactivity.this);             pdialog.setmessage("aguarde...");             pdialog.setcancelable(false);             pdialog.show();         }          @override         protected void doinbackground(string... params) {             httphandler sh = new httphandler();             txtdistanciatotal = (textview) findviewbyid(r.id.txtdistanciatotal);             txtduracaototal = (textview) findviewbyid(r.id.txtduracaototal);             instrucoes = (textview) findviewbyid(r.id.instrucoes);             string url1 = "https://maps.googleapis.com/maps/api/directions/json?origin=";             string url2 = "&destination=";             string url3 = "&key=aizasybh6tmmrc6qahmjewfgvgc8xojc0wmajxq&language=pt";             string latrepr = params[0];             string lngrepr = params[1];             final string jsonstr = sh.makeservicecall(url1 + mylatitude + "," + mylongitude + url2 + latrepr + "," + lngrepr + url3);             log.e(tag, "link: " + url1 + mylatitude + "," + mylongitude + url2 + latrepr + "," + lngrepr + url3);              log.e(tag, "resposta url: " + jsonstr);             if (jsonstr != null) {                 try {                     jsonobject root = new jsonobject(jsonstr);                     jsonarray routes = root.optjsonarray("routes");                     if (routes != null) {                         jsonobject singlerout = (jsonobject) routes.get(0);                         jsonarray legs = (jsonarray) singlerout.get("legs");                         if (legs != null) {                             jsonobject singleleg = (jsonobject) legs.get(0);                             //distancia total                             jsonobject distancet = (jsonobject) singleleg.get("distance");                             if (distancet != null) {                                 distt = distancet.getstring("text");                             }                             //duracao total                             jsonobject durationt = (jsonobject) singleleg.get("duration");                             if (durationt != null) {                                 durat = durationt.getstring("text");                             }                              jsonarray steps = (jsonarray) singleleg.get("steps");                             if (steps != null) {                                 (int j = 0; j < steps.length(); j++) {                                     jsonobject singlestep = (jsonobject) steps.get(j);                                     hashmap<string, string> direcao = new hashmap<>();                                     jsonobject distance = (jsonobject) singlestep.get("distance");                                     //distancia                                     if (distance != null) {                                         string dist = distance.getstring("text");                                         direcao.put("textdi", dist);                                     }                                     //duraçao                                     jsonobject duration = (jsonobject) singlestep.get("duration");                                     if (duration != null) {                                         string dura = duration.getstring("text");                                         direcao.put("textdu", dura);                                     }                                     //polylines                                     jsonobject singlepolyline = (jsonobject) singlestep.get("polyline");                                     if (singlepolyline != null) {                                         string points = singlepolyline.getstring("points");                                         map<string, string> caminho = new hashmap<>();                                         caminho.put("points", points);                                         listapolylines.add((hashmap<string, string>) caminho);                                     }                                     //instruções                                     string html = singlestep.getstring("html_instructions");                                     direcao.put("html_instructions2", html);                                     listadirecoes.add(direcao);                                 }                             }                         }                     }                 } catch (final jsonexception e) {                     log.e(tag, "error: " + e.getmessage());                     runonuithread(new runnable() {                         @override                         public void run() {                             toast.maketext(getapplicationcontext(), "error: " + e.getmessage(), toast.length_long).show();                         }                     });                 }             } else {                 log.e(tag, "error");                 runonuithread(new runnable() {                     @override                     public void run() {                         toast.maketext(getapplicationcontext(), "verifique sua ligação à internet", toast.length_long).show();                     }                 });             }              return null;         }          @override         protected void onpostexecute(void result) {             super.onpostexecute(result);              final listview list = (listview) (mapsactivity.this).findviewbyid(r.id.listadirecoes);             listadapter adapter = new simpleadapter(                     (mapsactivity.this),                     listadirecoes,                     r.layout.list_item_direcoes,                     new string[]{"html_instructions2", "textdi", "textdu"},                     new int[]{r.id.instrucoes, r.id.txtdistancia, r.id.txtduraçao});              list.setadapter(adapter);              txtduracaototal.settext(durat);             txtdistanciatotal.settext(distt);              fazercaminho(listapolylines);               if (pdialog.isshowing()) {                 pdialog.dismiss();             }              bottom_sheet.setontouchlistener(new view.ontouchlistener() {                  public boolean ontouch(view v, motionevent event) {                     log.v(tag, "parent touch");                     findviewbyid(r.id.listadirecoes).getparent().requestdisallowintercepttouchevent(false);                     return false;                 }             });             listadirecoeschild.setontouchlistener(new view.ontouchlistener() {                  public boolean ontouch(view v, motionevent event) {                     log.v(tag, "child touch");                     // disallow touch request parent scroll on touch of child view                     v.getparent().requestdisallowintercepttouchevent(true);                     return false;                 }             });         }     } 

you can go through call class class

private activity activity; 

you should initialize, activity

from class, call :

((detailsactivity) activity).refreshlist(latrepr, lngrepr); 

now in, detailsactivity.class can as,

public void refreshlist(string latrepr, string lngrepr) {       new getdirecoes().execute(latrepr, lngrepr);    } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -