Coder Social home page Coder Social logo

android-dagger2-example's Introduction

Hi there ๐Ÿ‘‹

My name is Ali. I am a coder and tech entrepreneur. I started as a self-taught coder to founding companies impacting 10 million users. I have seen technology evolve in the 10 years of my career and helped companies solve their challenging problems. I love to share my learning experience with the community through open-source projects, blogs, and videos.

Learn from my YouTube channel UnusualCode: youtube/@unusualcode

Find Me: janisharali.com

android-dagger2-example's People

Contributors

amitshekhariitbhu avatar janishar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-dagger2-example's Issues

How to keep the ActivityComponent

How to keep the ActivityComponent dependent on the ApplicationComponent? I get the unscoped error:

Error:(13, 1) error: com.joaquimley.daggerexample.di.component.ActivityComponent (unscoped) cannot depend on scoped components:
@singleton com.joaquimley.daggerexample.di.component.ApplicationComponent

[Question] why activityModule() is depreciated?

In mainactivity.java

    public ActivityComponent getActivityComponent() {
        if (activityComponent == null) {
            activityComponent = DaggerActivityComponent.builder()
                    .activityModule(new ActivityModule(this))
                    .applicationComponent(DemoApplication.get(this).getComponent())
                    .build();
        }
        return activityComponent;
    }

I am getting depreciate error on line no-30 i.e. .activityModule(new ActivityModule(this)).

If you could explain me why is it happening then it will be helpful?

How to use injectable class in non Activity/Fragment class

Hi ,
I'm currently using dagger 2 in my project. I'm unable to access injectable class through @Inject in non activity/fragment class. I have a handler class and want to use injectable in that class. Can u help me how to do this.

@Singleton
@Component(modules = {
        AndroidSupportInjectionModule.class,
        ApplicationModule.class,
        ActivityBuilder.class})
public interface ApplicationComponent extends AndroidInjector<DaggerApplication> {

    void inject(AppController appController);
    void inject(APIHandler apiHandler);

    @Override
    void inject(DaggerApplication daggerApplication);

    @Component.Builder
    interface Builder{
        @BindsInstance
        Builder application(Application application);
        ApplicationComponent build();
    }
}

This is my ApplicationComponent class I added a method inject(APIHandler apiHandler) in this and tried getting @Injent DataManager dataManager(injectable class) in ApiHandler class but getting it null, any other thing i need to do in APIHandler class.Let me know if i m missing something where as i m able to get it in activity and fragment

APIHandler class

public class APIHandler {
 
    /**
     * Activity reference object
     */
    private Activity mActivity;
    /**
     * Debug TAG
     */
    private String TAG = APIHandler.class.getSimpleName();
 @Inject
    DataManager dataManager;

    /**
     * Public Constructor for this class
     *
     * @param mActivity
     * @param webAPIResponseListener
     */
    public APIHandler(Activity mActivity, WebAPIResponseListener webAPIResponseListener) {
        this.mActivity = mActivity;
        this.mResponseListener = webAPIResponseListener;
        postAPICall();
    }
//API call
    public void postAPICall() {
//doing something
if(dataManager != null){
dataManager.setName();
}
}

DaggerActivityComponent missing

DaggerActivityComponent this class is missing in com.mindorks.example.android_dagger2_example.di.component package but still you used in
com.mindorks.example.android_dagger2_example.MainActivity class.
How?

DaggerActivityComponent file not found

The file not in the package- com.mindorks.example.android_dagger2_example.di.component.DaggerActivityComponent;

public ActivityComponent getActivityComponent() {
        if (activityComponent == null) {
            activityComponent = **DaggerActivityComponent**.builder()
                    .activityModule(new ActivityModule(this))
                    .applicationComponent(DemoApplication.get(this).getComponent())
                    .build();
        }
        return activityComponent;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.