This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onCreate() { | |
val viewModel = ... //initialize your view model | |
viewModel.data.observe(this, Observer { | |
//do operations based on the value | |
}) | |
viewModel.getData() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onCreate() { | |
val viewModel = ... //initialize your view model | |
viewModel.getData() | |
viewModel.data.observe(this, Observer { | |
//do operations based on the value | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onCreate() { | |
val viewModel = ... //initialize your view model | |
viewModel.getData() | |
viewModel.data.observe(this, Observer { | |
//do operations based on the value | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidTest | |
class HiltTest { | |
@get:Rule val hiltRule = HiltAndroidRule(this) | |
@Inject lateinit var apiService: ApiService | |
@Test | |
fun testFoo() { | |
hiltRule.inject() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainViewModel @ViewModelInject constructor(private val useCase: UseCase) : ViewModel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AndroidEntryPoint | |
class MainActivity : MyBaseActivity() { | |
@Inject lateinit var apiService: ApiService | |
override fun onCreate(savedInstanceState: Bundle?) { | |
// Injection happens in super.onCreate(). | |
super.onCreate() | |
// Do something with apiService ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
@InstallIn(ApplicationComponent::class) // Installs FooModule in the generate ApplicationComponent. | |
object AppModule { | |
@Provides | |
fun provideApiService(): ApiService {...} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component(modules = [ | |
ActivityModule::class, | |
ViewModelModule::class, | |
NetworkModule::class]) | |
interface AppComponent : AndroidInjector<DaggerApplication> { | |
@Component.Factory | |
interface Factory { | |
fun create(@BindsInstance application: Application): AppComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidApp | |
class App : Application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App : DaggerApplication() { | |
override fun applicationInjector() = DaggerAppComponent.factory().create(this) | |
} |
NewerOlder