java - I'm working on datasync service, with web api -
i working on datasync service, i'm getting json response webserver. question how pass response activity i'm calling service.
you can use eventbus , send data desired activity subscribing event.
for eg:
compile 'org.greenrobot:eventbus:3.0.0'
eventbus class
public class datasyn { public final list<yourmodel> yourmodel; public datasyn(list<yourmodel> yourmodel) { this.yourmodel = yourmodel; } }
send data response :
eventbus.getdefault().post(new datasyn(yourdatalist)); subscribe , receive data wherever need: @override public void onstart() { super.onstart(); eventbus.getdefault().register(this); } @override public void onstop() { eventbus.getdefault().unregister(this); super.onstop(); } @subscribe(threadmode = threadmode.main) public void ondatarecevied(datasyn event) { if (event.yourmodel != null) { populatedata(event.yourmodel); } }
above easiest way share data
Comments
Post a Comment