Skip to content

Instantly share code, notes, and snippets.

View hkhc's full-sized avatar
🏠
Working from home

Herman Cheung hkhc

🏠
Working from home
  • United Kingdom
View GitHub Profile
KClass 157782037 class myapp.ui.model.MyAppiewModel (Kotlin reflection is not available)
Class 157782037 class myapp.ui.model.MyAppViewModel
Log.d("CVM", "KClass ${MyAppViewModel::class.hashCode()} ${MyAppViewModel::class}")
Log.d("CVM", "Class ${MyAppViewModel::class.java.hashCode()} ${MyAppViewModel::class.java}")
KClass class myapp.ui.model.MyAppViewModel (Kotlin reflection is not available)
Class class myapp.ui.model.MyAppViewModel
Log.d("MyApp", "KClass ${MyAppViewModel::class}")
Log.d("MyAPp", "Class ${MyAppViewModel::class.java}")
ViewModelProviders.of(myFragment, viewModelFactory)[MyAppViewModel::class.java]
package myapp.di
import androidx.lifecycle.ViewModel
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoMap
import myapp.di.MyAppViewModel
import myapp.di.annotations.ViewModelKey
@Module
package myapp.di.annotations
import androidx.lifecycle.ViewModel
import dagger.MapKey
import kotlin.reflect.KClass
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
@MapKey
internal annotation class ViewModelKey(val value: KClass<out ViewModel>)
@hkhc
hkhc / SetValueTest.java
Created July 4, 2018 15:35
Test Activity with Robolectric
/*
* Copyright 2018 Herman Cheung
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Find the AndroidManifest.xml at
* 1. Java resource, or
* 2. build/intermediates/manifests/[full or fast-start]/[build-type],
* which is generated by merging the AndroidManifest.xml files in
* src/main or source folder of other build variants.
*/
@Runner(RobolectricTestRunner.class)
@Config(manifest="AndroidManifest.xml")
@hkhc
hkhc / create_avd.md
Last active July 12, 2023 20:16
Creating and launching Android emulator AVD properly

Creating AVD

avd_name=my_avd
api_level=23
abi=x86_64
tag=google_apis
device="Nexus 5" # list of available devices see below

${ANDROID_HOME}/tools/bin/avdmanager --verbose create avd --name ${avd_name} \