Questions tagged lifecycle

Explore the latest questions and answers asked by our top developers.

Android different ways to create viewModel object which one to use when?

I recently started with the ViewModel and AndroidViewModel, I see there are different approach to initialise a viewModel instance, for me all works fine, I just want to know which one to use when? and where should I initialise the viewModel object? following are the all the different approach that works for me: val myViewModel1 […]

Categorized as android, lifecycle, mvvm, viewmodel

Lifecycle OnLifecycleEven tis deprecated

After updating lifecycle library to 2.4.0 Android studio marked all Lifecycle events as deprecated. @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) fun create() { tts = TextToSpeech(context, this) } @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) fun stopTTS() { tts?.stop() } Is there any equivalent replacement such as DefaultLifecycleObserver ? Source: Android Questions

By Vahe Gharibyan
Categorized as android, java, kotlin, lifecycle

Does Android reuse intent bundle for rebuilding

I have a question about rebuilding of an fragment please : if a fragment is killed then reconstructed, have Android kept the bundle from the intent that created the fragment initially ? In order to rebuild it as is ? I have not found any place talking about it (only about SavedStateBundle), so the answer […]

By AdrienM
Categorized as android, fragment, lifecycle

Callback when task goes into background or comes into foreground?

I have an activity A, it launches custom-tab. I need to know while the custom tab is open, if the task (of which the activity is part of) goes to background or comes to foreground. I am aware of this question How to detect when an Android app goes to the background and come back […]

Full-Screen-Gesture while in pinning screen Android 10

I need to disable two full-screen-gesture in my app. I do’t want my app disturb by other apps, so I use "screen-pinning" function to force my app on the top layer, and it work on devices with traditional "Task-Home-Back" buttons at bottom. The screen-pinning function can disable them automatically. But I met some trouble on […]

The minCompileSdk (android-30). Dependency: androidx.lifecycle:lifecycle-livedata-ktx:2.4.0

The minCompileSdk (31) specified in a dependency’s AAR metadata (META-INF/com/android/build/gradle/ is greater than this module’s compileSdkVersion (android-30). Dependency: androidx.lifecycle:lifecycle-livedata-ktx:2.4.0. Source: Android Questions

By Kashif Ali
Categorized as activity-lifecycle, android, android-studio, java, lifecycle

SharedViewModel between fragment1 recyclerAdapter and fragment2

I could transfer data between fragments. when it has a recyclerView in one of fragments. How to Transfer recyclerView Item data to another fragment? A temp solution, I put in LifecycleOwner and SharedViewModel in RecyclerViewAdapter’s params. class SharedViewModel : ViewModel() { val selectedBean = MutableLiveData<VehicleQueueResponse>() fun selectBean(vehicleQueueResponse: VehicleQueueResponse){ selectedBean.value = vehicleQueueResponse } } adapter = […]

By yan sam
Categorized as adapter, android, android-recyclerview, lifecycle, viewmodel

android onpause not called when using navgraph

Using androids navgraph/navhost seems useful. However the lifecycle of fragments has changed when compared to the previous fragmentmanager method replace. Prevoiusly I called replace with fragment manager and the fragments onPause method was called before transitioning to a new fragment ensuring I had notice the user had navigated away. Now, using a navgraph, the onresume […]

By cagney
Categorized as android, fragment, lifecycle

What is the proper usage Android Lifecycle

I’m new to android development. And I start to learn about android lifecycle create(),start(),resume(),…etc. I have a doubt on that when to use how to use efficiently I googled many and can’t find the exact one. can you pls explain breifly about this? Source: Android Questions

By Mr Sudharsan
Categorized as android, lifecycle

In which lifecycle method , we should observe a livedata object?

In which method should you observe a livedata object? onResume() onRestart() onCreate() ondestroy() please include reason as well. Source: Android Questions

By Anshika Choudhary
Categorized as android, android-livedata, lifecycle, viewmodel
1 2 3 5

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us