frogermcs / githubclient Goto Github PK
View Code? Open in Web Editor NEWExample of Github API client implemented on top of Dagger 2 DI framework.
Example of Github API client implemented on top of Dagger 2 DI framework.
I really love your app as a model for DI for my own! Here's one design problem:
Sometimes Android kills an app process in the background because of low memory. It restarts it automatically when it come back.
(This is different from killing and restarting activities: for a good review see here http://stackoverflow.com/questions/14375720/android-destroying-activities-killing-processes)
Your app crashes under such conditions, if you are not on the startup activity, since the user component is not recreated. The reason is that Android when restarting the app, Android recreates the app object, then the topmost activity (not the earlier ones, until they come into view).
You can verify in your own app by turning on the Developer Option...Background process limit to zero, then drilling down into a user, then switching away from your app and back. The app crashes.
It would be cool to see how you would modify your app and your design pattern to deal with this.
Is the url 2.1-SNAPSHOT on Sonatype.org still avaliable?
How should i set "build.grale" for dagger-compiler-2.1
When i am compile app in 4.4 it it gives error in marshamallow it is working perfect .
8-04 14:33:18.342 10759-10759/com.app.readyb E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.readyb, PID: 10759
java.lang.NoClassDefFoundError: com.app.readyb.config.ApplicationModule_ProvideContextFactory
at com.app.readyb.config.DaggerAppComponent.initialize(DaggerAppComponent.java:70)
at com.app.readyb.config.DaggerAppComponent.<init>(DaggerAppComponent.java:58)
at com.app.readyb.config.DaggerAppComponent.<init>(DaggerAppComponent.java:35)
at com.app.readyb.config.DaggerAppComponent$Builder.build(DaggerAppComponent.java:174)
at com.app.readyb.ReadyBApp.onCreate(ReadyBApp.java:68)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1030)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4409)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Thank you for your sharing this tutorial, it s very helpful
I am using your idea about User Scope to share signed user instance across it's sub components. And I want to make UserComponent itself be sub component of another one, like Base Activity Component.
My graph is
App component > base activity component > User Component > User Details Component (and many others)
The arrow stands for sub-component relationship.
In your example, you used SubComponent Builder to create User component, how can i make it extends all resource provide by App component and Base Activity component?
SplashActivityTests
never completes.
java.lang.VerifyError: frogermcs/io/githubclient/ui/activity/SplashActivity$AjcClosure1
at frogermcs.io.githubclient.ui.activity.SplashActivity.onCreate(SplashActivity.java:46)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Hi, when I build this project with gradle build tool 2.1.0 and run the app, I get the above error. But after reverting gradle to 2.0.0, this error disappear, I do not know why this happens.
We need new presenter on every activity creation anyways. If it is to handle activity recreation then the associated component will also be recreated which in turns results in new presenter object.
Hi Mirosław!
Thanks for the tutorials and introduction to Dagger 2. After some research, a common issue with using ReactiveX programming for Android applications is properly handling unsubcribes when the Activity is destroyed. How is it handled here? Should the Presenters also have an "onDestroy" method which is called by the Activity when it is getting destroyed? Or is Dagger 2 somehow helping us here?
Thanks!
-- Charles
Why ActivityScope
does not have @Retention(RetentionPolicy.RUNTIME)
while UserScope
does. Is there any good reason or just copy paste bug?
GithubClient/app/src/main/java/frogermcs/io/githubclient/GithubClientApplication.java:6: error: package com.frogermcs.androiddevmetrics does not exist
import com.frogermcs.androiddevmetrics.AndroidDevMetrics;
This is because the com.frogermcs.androiddevmetrics
plugin only adds source for the debugCompile variant
What if user opens RepositoriesListActivity and then goes in background. System can kill application process, and then when user will try to open app back to foreground - RepositoriesListActivity will be restored and GithubClientApplication.get(this).getUserComponent() will return null object, which will produce nullpointer exception. Is am I missing something?
Hi !
First congrats for you tuto, thank you for sharing your knowledge with us.
Why didn't you committed the userComponent release logic as described in this gist in the repository ?
https://gist.github.com/frogermcs/f1d0c916d91d1a341e4a#file-githubclientapplication-java
I am interested in when you actually call that releaseUserComponent method.
Hi,
in GithubClientApplication.java file there's the creation of the global dependencies graph
DaggerAppComponent.builder()
.appModule(new AppModule(this))
.githubApiModule(new GithubApiModule())
.build();
But where is the DaggerAppComponent class in the project? I couldn't find it. I'm missing something?
Thanks
Nico
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.