Category : lifecycle

I need to insert the data I got from firebase to a LiveData<List>, I’m not sure how to do so public LiveData<List<MedicationViewModel>> getAllMeds(){ mDatabase.addListenerForSingleValueEvent(new ValueEventListener() { LiveData<List<MedicationViewModel>> medics; //Return this @Override public void onDataChange(DataSnapshot dataSnapshot) { for(DataSnapshot ds : dataSnapshot.getChildren()) { MedicationViewModel medic = ds.getValue(MedicationViewModel.class); Log.d("TAG", medic.getMedName()); //TODO } } @Override public void onCancelled(DatabaseError databaseError) ..

Read more

I will demonstrate my query using the following code snippet: Code Example public class MyStorage { public MyStorage(Context context) { // do staff with context } public void func() {} } public class MySingelton { private static MySingelton instance; private MyStorage myStorage; // … and other members public static MySingelton getInstance() { if (instance == ..

Read more

In onCreate of my Activity I create a ViewModel after calling super.onCreate: super.onCreate(savedInstanceState); model = new ViewModelProvider(this).get(OrbitsViewModel.class); At the end of onCreate I call: model.getLiveData().observe(this, this::updateInUiThread) This worked perfect for a long time and for many versions of my app. Recently I updated libraries to androidx.activity:activity:1.2.0 and androidx.lifecycle:lifecycle-common-java8:2.3.0. The result is many crashes in Play ..

Read more

Hello and already thanks for your time, i appreciate it. I have the following problem and would be happy, if someone could help me: Because I am a beginner in Android Studio using Kotlin, I wanted to just make a little app for taking notes. For this problem, i am looking the internet up and ..

Read more