android-architecture-components

Reacting to activity lifecycle in ViewModel

好久不见. 提交于 2021-02-18 04:39:38
问题 I'm trying to create an app which will use MVVM architecture and there's one thing I quite don't understand. Official Android docs say that's not a good idea to reference activity context in ViewModel's (as ViewModel may outlive activity) so I've started to wonder about usecase when I want to execute some action when my activity is resumed. I know ViewModel's shouldn't do business logic themselves but even if I use some service class (let's say GPSService which has to start and pauseeach time

Reacting to activity lifecycle in ViewModel

人盡茶涼 提交于 2021-02-18 04:39:21
问题 I'm trying to create an app which will use MVVM architecture and there's one thing I quite don't understand. Official Android docs say that's not a good idea to reference activity context in ViewModel's (as ViewModel may outlive activity) so I've started to wonder about usecase when I want to execute some action when my activity is resumed. I know ViewModel's shouldn't do business logic themselves but even if I use some service class (let's say GPSService which has to start and pauseeach time

Reacting to activity lifecycle in ViewModel

人盡茶涼 提交于 2021-02-18 04:38:34
问题 I'm trying to create an app which will use MVVM architecture and there's one thing I quite don't understand. Official Android docs say that's not a good idea to reference activity context in ViewModel's (as ViewModel may outlive activity) so I've started to wonder about usecase when I want to execute some action when my activity is resumed. I know ViewModel's shouldn't do business logic themselves but even if I use some service class (let's say GPSService which has to start and pauseeach time

Reacting to activity lifecycle in ViewModel

白昼怎懂夜的黑 提交于 2021-02-18 04:38:08
问题 I'm trying to create an app which will use MVVM architecture and there's one thing I quite don't understand. Official Android docs say that's not a good idea to reference activity context in ViewModel's (as ViewModel may outlive activity) so I've started to wonder about usecase when I want to execute some action when my activity is resumed. I know ViewModel's shouldn't do business logic themselves but even if I use some service class (let's say GPSService which has to start and pauseeach time

Does Android Jetpack require the use of the Kotlin language?

雨燕双飞 提交于 2021-02-16 10:01:58
问题 I can't seem to find a clear answer to this in Google, and all the documentation and samples I've seen for Jetpack seem to refer to and use Kotlin. But do you HAVE to use Kotlin in order to use Jetpack? Or can Jetpack be used with traditional Java programs? I was looking at Kotlin but it adds almost a MB to your app size. And seeing as my entire app is only about 200KB currently, I don't think Kotlin is worth increasing the size of my app by 500%! 回答1: Jetpack is a collection of libraries

Android LiveData: Transformation switchMap: Apply filter on the original list and show the filtered data

泪湿孤枕 提交于 2021-02-11 16:51:27
问题 public class FlightViewModel extends BaseViewModel { private FlightRepository flightRepository; private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mSearchFlights = new MediatorLiveData<>(); private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mOriginalList = new MediatorLiveData<>(); private MediatorLiveData<Resource<FlightSearchMainOuterModel>> mSortedSearchFlights = new MediatorLiveData<>(); public FlightViewModel(@NonNull Application application) { super(application);

When / How to Create / Destroy Room Database

微笑、不失礼 提交于 2021-02-11 13:38:39
问题 I was wondering if someone could either point me to documentation to / clarify when to create or destroy a room database instance. Also how you would effectively open / close it ? If I have a RoomDatabase object that gets injected via dagger to a presenter is that cool and then I just access various Daos? I'm worried about having the object lingering and taking up memory. 回答1: Instead of Injecting the RoomDatabase into your presenter you could Inject a DataManager Singleton class. This

Object is changed after sending it to another Fragment

回眸只為那壹抹淺笑 提交于 2021-02-11 06:16:48
问题 So, I have a really weird issue, I pass an object from Fragment A to Fragment B , I modify this object in a new instance in Fragment B, but after I change a value on this object it also changes that value when I pop Framgment B and that object keeps modified now also for Fragment A Fragment A ... override fun onItemClick(v: View?, position: Int) { searchView.clearFocus() val bundle = Bundle() bundle.putSerializable("shop", landingAdapter.getItem(position)) findNavController().navigate(R.id

Object is changed after sending it to another Fragment

旧城冷巷雨未停 提交于 2021-02-11 06:16:48
问题 So, I have a really weird issue, I pass an object from Fragment A to Fragment B , I modify this object in a new instance in Fragment B, but after I change a value on this object it also changes that value when I pop Framgment B and that object keeps modified now also for Fragment A Fragment A ... override fun onItemClick(v: View?, position: Int) { searchView.clearFocus() val bundle = Bundle() bundle.putSerializable("shop", landingAdapter.getItem(position)) findNavController().navigate(R.id

Object is changed after sending it to another Fragment

情到浓时终转凉″ 提交于 2021-02-11 06:16:07
问题 So, I have a really weird issue, I pass an object from Fragment A to Fragment B , I modify this object in a new instance in Fragment B, but after I change a value on this object it also changes that value when I pop Framgment B and that object keeps modified now also for Fragment A Fragment A ... override fun onItemClick(v: View?, position: Int) { searchView.clearFocus() val bundle = Bundle() bundle.putSerializable("shop", landingAdapter.getItem(position)) findNavController().navigate(R.id