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
51
votes
13 answers

: 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 view holder's onBind and the response is updating the UI. In order to do so, I have to…
Utkarsh Singh
  • 511
  • 1
  • 4
  • 3
51
votes
3 answers

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 service for the location logging. I store the locations in a Room Database which is…
47
votes
9 answers

NavUtils.navigateUpTo() does not start any Activity

I have two activities MainActivity DeepLinkActivity I set up everything to use the NavUtils for navigating up like advised here, here and here. What I want to achieve is: Start DeepLinkActivity via a deep link Press up Go to…
flx
  • 14,146
  • 11
  • 55
  • 70
46
votes
8 answers

View pager and fragment lifecycle

I have a ViewPager that loads three pages at a time. If I swipe from page 1 to page 2 then to 3, the first page(fragment) goes to onPause(). Then, if I swipe to the second page, 1st page comes to onResume() even though the page 1 is still not…
shreyas
  • 2,166
  • 3
  • 18
  • 30
45
votes
6 answers

What is lifecycle observer and how to use it correctly?

I have read about new architectural components in Android. So, i wanted to ask what are lifecycle observers and why do we need them? In what cases it is useful? Thanks for your answer!
Nazarii Moshenskiy
  • 1,802
  • 2
  • 16
  • 35
44
votes
4 answers

Android lifecycle library: Cannot add the same observer with different lifecycles

I have an app I'm working on that's using the lifecycle library but I'm getting an IllegalArgumentException that says "Cannot add the same observer with different lifecycles" I only add observers in onCreate which I thought would be safe. Most of my…
TheHebrewHammer
  • 3,018
  • 3
  • 28
  • 45
44
votes
7 answers

Android how to stop refreshing Fragments on tab change

I have the following code : MainActivity.java package com.erc.library; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import…
44
votes
6 answers

when is onRestoreInstanceState called?

Sorry for my incomprehension, but I am new in the android development. I have an application with activity A and activity B in it, and I go from activity A to activity B. When I left activity A, the onSaveInstanceState method was called, but when I…
41
votes
5 answers

How to handle AsyncTask onPostExecute when paused to avoid IllegalStateException

I appreciate the numerous postings regarding AsyncTask on a rotation change. I have the following problem when using the compatability lib and trying to dismiss a DialogFragment in onPostExecute. I have a fragment which fires of an AsyncTask which…
PJL
  • 18,735
  • 17
  • 71
  • 68
40
votes
3 answers

Android - Performing stop of activity that is not resumed

When I push my app to background, and do some other stuff like whatsapp or sms, onResume it works great. But I recently discovered that when I open/launch facebook app while my app is on background, I don't know what happens... But onResume, the…
Salmaan
  • 3,543
  • 8
  • 33
  • 59
39
votes
3 answers

Android - While switching between two activities, the calling order of lifecycle methods of Activity

I want to start an Activity (SECOND Activity) from another Activity (FIRST Activity) by calling startActivity(intent). Before I actually do it, I found people say that the lifecycle methods are called in the following order: FIRST Activity…
Naetmul
  • 14,544
  • 8
  • 57
  • 81
37
votes
1 answer

fragment lifecycle: when "ondestroy" and "ondestroyview" are not called?

Imagine this scenario: I have a Fragment in a Pager. I try to switch to other apps, so that the Activity owning my pager (and my fragment) will be stopped and temporarily destroyed, eventually. So, when I come back to my Activity, the Fragment's…
Bertuz
  • 2,390
  • 3
  • 25
  • 50
36
votes
4 answers

Android DialogFragment disappears after orientation change

I have a FragmentActivity support v4 class which implements two side by side (kind of like gmail) fragments and a button which can bring up a DialogFragment. This all works great unless I have an orientation change. When I have an orientation…
34
votes
3 answers

Is it mandatory to remove yourself as an observer from Android Lifecycle?

I am building an Android Java class which implements the LifecycleObserver interface. This is the constructor: public MyObserver(AppCompatActivity activity) { this.mActivity = new WeakReference(activity); …
esilver
  • 27,713
  • 23
  • 122
  • 168
34
votes
8 answers

Activity did not call finish? (API 23)

I am getting the following error and i have no clue as to why its happening. Error: 08-23 17:07:46.533 22454-22454/com.a.b.c E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.a.b.c, PID: 22454 java.lang.RuntimeException: Unable to resume…
olfek
  • 3,210
  • 4
  • 33
  • 49