This is my ViewModel class which extends AndroidViewModel
If i want to add event on viewmodel class using databinding, can i launch intent in viewmodel class?
public class MyViewModel extends AndroidViewModel {
private BookRepository bookRepository;
private LiveData<List<Book>> mAllBooks;
public MyViewModel(@NonNull Application application) {
super(application);
this.bookRepository = new BookRepository(application);
this.mAllBooks = bookRepository.getAllBooks();
}
LiveData<List<Book>> getAllBooks() { return mAllBooks; }
public void insert(Book book) { bookRepository.insert(book); }
public void update(Book book) { bookRepository.update(book); }
}
Now i'm launch intent events on MainActivity like this
public void clickBtn(){
Intent intent = new Intent(this, AddActivity.class);
intent.putExtra("Request", REQUEST_CODE);
launcher.launch(intent);
}
Are there any better ways to start event or intent related events on ViewModelClass?