There is a model for kotlin :
import android.arch.lifecycle.ViewModel class TestModel<V : TestView> : ViewModel() { fun attach(view: V) { Log.d("testLog", "TestModel - attach() = $view") } } Interface:
interface TestView { fun showError() } There is an Activity using it on java :
import android.arch.lifecycle.ViewModelProviders; public class TestActivity extends AppCompatActivity implements TestView { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); TestModel model = ViewModelProviders.of(this).get(TestModel.class); model.attach(this); } @Override public void showError() {} } The code is working. How to convert TestActivity to kotlin ? I also tried to use the built-in converter in Android Studio , I failed.
ViewModel, no references to activations! There will be memory leaks. - Eugene Krivenja