Category "android-lifecycle"

Android activity loses data when switching between apps

I'm writing my first Android app. Essentially it shows and controls the score of a straight pool match. I've read articles about the lifecycle of an activity bu

Jetpack compose - how do I refresh a screen when app returns to foreground

I need to automatically refresh an Android Compose screen when the app returns to the foreground. I have an that requires permissions and location services. If

Adding function to foreground service lifecycle methods can create an issue? Is this best practise?

I created a timer app. So it's counting time basically and I'm saving the time to room when service close in OnDestroy scope. Is it best practise? Or is there a

Activity Conditional Flow

I have a movie ticket booking app. My initial activity is the login activity where there is a "continue as guest" option in case he doesn't want to sign in or r

IllegalStateException: Fragment already added in the tabhost fragment

FATAL EXCEPTION: main Process: com.example.loan, PID: 24169 java.lang.IllegalStateException: Fragment already added: FormFragment{428f10c8 #1 id=0x7f050055 form

How to know when my app has been killed?

I need to know when the user kills my app (Force stop). I've been reading the android lifecycle, which has the onStop() and onDestroy() functions, these are rel

Lifecycle callbacks for system activity (PickActivity / Intent.ACTION_GET_CONTENT)

I am working on an Android app that needs to perform a clean-up task (disconnect BLE devices) when the whole application goes to background. I implemented the s

Minimal android foreground service killed on high-end phone

I'm trying to create an app that lets users log routes (locations/GPS). To ensure locations are logged even when the screen is off, I have created a foreground

In Activity.onCreate(), why does Intent.getExtras() sometimes return null?

This was probably a false alarm, see my own answer. Original question below: An activity has a button that takes the user to another activity. To launch the ne

Android MVVM - How to reference Activity in ViewModel

MVVM architecture, this is my View (Activity): private MyApp app; private MainActivityVM viewModel; @Override protected void onCreate(Bundle savedInstanceSta

How do I return function value in lifecycle-aware coroutine scope in Android?

fun returnValue(): Int { viewModelScope.launch { return 1 // Something like this } } I want to return some value in a viewModelScope like the

: Can't access the Fragment View's LifecycleOwner when getView() is null i.e., before onCreateView() or after onDestroyView()

I am using live data in my application for all the network calls and response handling. In one of the scenarios, my recycler view is loading some data in its v