KayCee
06/29/2020, 4:42 AM@Provides
@Singleton
fun provideMediaPlayer(): MediaPlayer {
return MediaPlayer.create(applicationContext, R.raw.sample)
}
//AppComponent
@Component(modules = [AppModule::class])
@Singleton
interface AppComponent {
fun inject(activity: MainMusicActivity)
fun inject(fragment: FeaturedFragment)
fun inject(fragment: MyMusicFragment)
}
This is inject in fragment, I try both @Inject and @Inject set
@Inject
lateinit var mediaPlayer: MediaPlayer
My question is am I using dagger correctly? Or is there any better way for getting singleton instance of media player with these view pager fragmentsJakub
06/30/2020, 12:18 AMAhmed Ibrahim
06/30/2020, 11:04 AMinject(fragment)
call?