android-architecture-components

Android ViewModel recreated when its Host Activity was not in the top of Activity Stack and the device was rotated

匆匆过客 提交于 2019-12-21 12:54:39
问题 I am in the following scenario: I have an OnboardActivity which contains a ViewModel , I can rotate this OnboardActivity many times and the ViewModel persist across configuration changes without issues. However, if I launch another Activity(FirebaseAuthActivity) on top of this one ( OnboardActivity ) with startActivityForResult(...) , and then in FirebaseAuthActivity I rotate the device and press the back button. When the OnboardActivity is brought to the top of the stack it recreates the

Is WorkerManager a realiable way to implement alarm/reminder feature in the app?

不打扰是莪最后的温柔 提交于 2019-12-21 07:36:06
问题 We notice that AlarmManagerCompat alone, isn't a reliable way to implement alarm/ reminder feature in our app, due to different AlarmManager behaviour in different version of OS. (For instance, Doze mode) Initially, we plan to use Evernote's android-job library, to help us implement alarm/ reminder feature in our app. However, along the way, we also notice that Google just release WorkerManager . So far, WorkerManager works well for us, when we run some one-time background jobs (Almost

Accessing BroadCastReceiver in Viewmodel

不打扰是莪最后的温柔 提交于 2019-12-21 04:48:22
问题 I am struggling in choosing the right way to pass data from broadcastReceiver to ViewModel and from there I pass data to my Repository and update LiveData. I use FCM push notifications and have local broadCastReceiver which uses ActivityLifecycle. I found that it is bad practice to access ViewModel from BroadcastReceiver, but not sure why? If I manage lifecycle of broadcastReceiver it should not cause any problems... So what is the best way to pass received data from FCM to my Repository's

add unique constraint in room database to multiple column

狂风中的少年 提交于 2019-12-21 03:34:53
问题 I have one entity in room @Entity(foreignKeys ={ @ForeignKey(entity = Label.class, parentColumns = "_id", childColumns = "labelId", onDelete = CASCADE), @ForeignKey(entity = Task.class, parentColumns = "_id", childColumns = "taskId", onDelete = CASCADE) }) public class LabelOfTask extends Data{ @ColumnInfo(name = "labelId") private Integer labelId; @ColumnInfo(name = "taskId") private Integer taskId; } sql syntax of this entity is as below CREATE TABLE `LabelOfTask` ( `_id` INTEGER PRIMARY

add unique constraint in room database to multiple column

被刻印的时光 ゝ 提交于 2019-12-21 03:34:30
问题 I have one entity in room @Entity(foreignKeys ={ @ForeignKey(entity = Label.class, parentColumns = "_id", childColumns = "labelId", onDelete = CASCADE), @ForeignKey(entity = Task.class, parentColumns = "_id", childColumns = "taskId", onDelete = CASCADE) }) public class LabelOfTask extends Data{ @ColumnInfo(name = "labelId") private Integer labelId; @ColumnInfo(name = "taskId") private Integer taskId; } sql syntax of this entity is as below CREATE TABLE `LabelOfTask` ( `_id` INTEGER PRIMARY

ViewModel is created again for the fragment

寵の児 提交于 2019-12-21 01:47:28
问题 I create viewmodel in MainFragment: @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ... MainViewModel mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class); ... } When user select item then navigate to Details fragment, this transaction is added to backstack. getFragmentManager() .beginTransaction() .replace(R.id.root, Details.newInstance()) .addToBackStack(null) .commit(); When user press back in

Pre-launch-report failures due to missing methods (in com.google.android.apps.mtaas.crawler-1/base.apk)

半世苍凉 提交于 2019-12-20 12:05:35
问题 Since recently my app started to contain strange error messages in the pre-launch reports (automatically generated after upload to the Play store). These reports contain exceptions such as the following: Exception java.lang.NoSuchMethodError: No interface method a(Landroid/arch/lifecycle/e;Landroid/arch/lifecycle/b$a;)V in class Landroid/arch/lifecycle/GenericLifecycleObserver; or its super classes (declaration of 'android.arch.lifecycle.GenericLifecycleObserver' appears in /data/app/com

Where is the source code of Android Architecture Components?

大兔子大兔子 提交于 2019-12-20 09:39:10
问题 Can't find the source code of new Android Architecture Components. Was it published? If it was, where? If the source is in AOSP, please specify which specific repo project should I use with repo sync [PROJ_NAME] in order to get it. 回答1: Here is the source for Lifecycle, Room, Paging and ViewModel. 回答2: As confirmed by Adam Powell, the source code of Architectural Components can be obtained only with the artifacts themselves: 回答3: As stated in Android team's official blog AndroidX Development

Room attempt to re-open an already closed database

假如想象 提交于 2019-12-20 09:28:06
问题 When using Room from the Android Architecture Components, I received the following error when attempting to access the database using a Dagger component: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: (database path) I was using Dagger version 2.11 and Room version 1.0.0-alpha7 . The error was reproducible on version 1.0.0-alpha5 . This error occurred on any attempt to access the database through a DAO after initialising the database and

Reusable generic base class DAOs with Android Room

人盡茶涼 提交于 2019-12-20 08:41:27
问题 Is there any way to create reusable generic base class DAOs with Android Room? public interface BaseDao<T> { @Insert void insert(T object); @Update void update(T object); @Query("SELECT * FROM #{T} WHERE id = :id") void findAll(int id); @Delete void delete(T object); } public interface FooDao extends BaseDao<FooObject> { ... } public interface BarDao extends BaseDao<BarEntity> { ... } I haven't been able to figure out any way of achieving this without having to declare the same interface