Questions tagged [android-lifecycle]

Questions regarding the events forwarded by the system to components, during their lifetime, in an Android Application. Most components have a specific LifeCycle that is imposed upon them. This tag is not meant to be used alone: use with the [android-activity], [android-service] and [android-broadcastreceiver] tags.

Questions regarding the events forwarded by the system to components, during their lifetime, in an Android Application. Most components have a specific LifeCycle that is imposed upon them. This tag is not meant to be used alone: use with , , , or

Android Activity Lifecycle

Activity and Fragment Lifecycle Diagram

2414 questions
0
votes
1 answer

Call onCreateOptionsMenu when page is loaded

I have a little problem I want show a menu in my action bar when own_product is true but when i change the value of my boolean the menu it still not visible, the boolean var change later. private var own_product = false override fun…
Gsliii
  • 3
  • 3
0
votes
1 answer

Android repeatOnLifecycle in fragment inside ViewPager2

If I add the following code snippet to a "normal" fragment it gets started and cancelled as expected when navigating to and from the fragment, but if I add this to fragment inside a view pager 2 it is not cancelled even though the fragmens onPause…
Kimble
  • 7,295
  • 4
  • 54
  • 77
0
votes
1 answer

savedInstanceState bundle is always null after device rotation

(I know this question has been asked many times before, but none of the answers that I have read have helped.) After I rotate my device, my fragment is recreated but the Bundle received in onCreate/onViewStateRestored/etc. is always null. The…
titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
0
votes
0 answers

ViewPager2 How to Update Data Before a Fragment becomes visible instead of relying on onResume()

I'm migrating to ViewPager2. In my fragments, I have data on these pages that are dynamic and could be changed depending on what has happened on other pages. Currently, I'm updating the data in the onResume() of my fragments. In ViewPager 1, the…
0
votes
1 answer

Set text color in fragment

I am trying to set text color in fragment. It crash slowly when I exit the fragment. I attached my code for reference.... class TickData implements Runnable { @Override public void run() { if (!token.isEmpty()){ …
0
votes
1 answer

Android - Jetpack - Make lazily created class lifecycle aware

Got an interesting case to solve. Backstory I have a ViewModel that is a LifecycleObserver, I'm following a nice architectural pattern where this VM is serving the overall screen logic, and is composing smaller VMs inside to serve components that…
Ahmed Ashraf
  • 2,795
  • 16
  • 25
0
votes
1 answer

Viewmodel crash after on onactivityresult, Can not perform this action after onSaveInstanceState

I am trying a simple flow, from my activity I open the file picker then to viewmodel and this gives me a the following crash: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState And here is the code that creates…
0
votes
0 answers

Managing code in onResume() of Android Activity

The need is something like this : If there is Location Permission Enable, Have to check that GPS is enable or not, If GPS is enable it's fine to continue for further flow - this working fine. But, If GPS is not enable, Requesting to enable it from…
Jaimin Modi
  • 1,530
  • 4
  • 20
  • 72
0
votes
1 answer

When is a Viewmodel's constructor called in Android?

I'm going through this codelab: https://developer.android.com/codelabs/android-lifecycles#6 It explains how to use SavedStateHandle in a ViewModel to survive process death. The constructor of the ViewModel is as below: private SavedStateHandle…
Neeraja Gandla
  • 97
  • 1
  • 6
  • 17
0
votes
1 answer

PictureInPicture mode Activity lifecycle problem

I have declared an activity (RoomActivity) in my Manifest.xml to be able to go in PipMode. Inside that activity i have a RoomFragment which is placed through the NavigationComponent library in the activity. room_activity.xml
0
votes
0 answers

MutableStateFlow: Cannot invoke setValue on a background thread from Coroutine on ActivityLifecycleCallbacks

Problem I got error message Cannot invoke setValue on a background thread when using MutableStateFlow on ActivityLifecycleCallback, i got this error after updating lifecycle jetpack to 2.4.0 and use repeatOnLifecycle. Calling network interfaces…
0
votes
1 answer

keep websocket open when app goes background in Tinder/Scarlet Websocket

in Jetpack Compose (1.0.4) I am using Tinder/Scarlet(2.4.0) for connecting WebSocket implementation 'com.github.Tinder.Scarlet:scarlet:0.2.4' implementation 'com.github.Tinder.Scarlet:scarlet-lifecycle-android:0.2.4' implementation…
ArtixModernal
  • 661
  • 2
  • 8
  • 21
0
votes
0 answers

Why would a LiveData observed with viewLifecycleOwner get callbacks after onDestroyView?

I have a Fragment that’s using View Binding, so it sets its _binding member variable in onCreateView and nulls it out in onDestroyView. In onViewCreated, I observe a LiveData from the view model using viewLifecycleOwner as the LifecycleOwner. (In…
0
votes
0 answers

How to receive an activity result in a separate class with registerForActivityResult

I'm trying to launch a intent from a separate class of my FragmentActivity to show the Biometric Settings to help user to enroll a biometric. But I'm getting a null from the observer and I don't know why. I'm following this…
0
votes
1 answer

How to use Room Database Viewmodel Observer in Android Foreground Service

I have following view model and observer in A Fragment(in onViewCreated) which populates the recyelerview using adapter commonOwnDBViewModel = new ViewModelProvider(requireActivity()).get(CommonOwnDBViewModel.class); …
1234567
  • 2,226
  • 4
  • 24
  • 69
1 2 3
99
100