square - Dagger scopes in Android -
jake wharton's talk @ devoxx 2013, architecting android applications dagger, talked creating dagger scope logged in users only. sort of thing sounds clean, , want in applications.
the code discussed in talk along lines of:
public class loggedinactivity extends activity { @inject user user; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_logged_in); daggerscopesapp app = (daggerscopesapp) getapplication(); app.getobjectgraph().plus(new usermodule("exampleusername")).inject(this); findviewbyid(r.id.do_something_button).setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { toast.maketext(loggedinactivity.this, user.username + " : " + user.somevalue++, toast.length_short).show(); } }); } }
however, if injected user scoped @singleton, it's properties disappear on config change (as object graph created in oncreate).
the solution pretty simple, can "plus" operation once , store new object graph somewhere else (maybe application class), wondering if approach? can square can provide insight in applications? not have singleton objects in "logged-in" graph?
the solution pretty simple, can "plus" operation once , store new object graph somewhere else (maybe application class), wondering if approach?
yep. logged-in graph's lifecycle needs live long user logged in , process around. since activity's lifecycle extremely short, isn't place it.
i used example ease people concept using familiar with.
can square can provide insight in applications?
all graphs aren't tied ui managed application
class. through guaranteed it's created once, created first, , disappears if process dies.
anything ui-related (activity-scope graphs, fragment-scope graphs, etc.) plussed on top of these ui comes , goes.
Comments
Post a Comment