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
717
votes
28 answers

How to start new activity on button click

In an Android application, how do you start a new activity (GUI) when a button in another activity is clicked, and how do you pass data between these two activities?
Adham
  • 63,550
  • 98
  • 229
  • 344
373
votes
3 answers

Difference and uses of onCreate(), onCreateView() and onActivityCreated() in fragments

What are the differences between onCreate(), onCreateView(), and onActivityCreated() in fragments and what would they each be used for?
243
votes
18 answers

On logout, clear Activity history stack, preventing "back" button from opening logged-in-only Activities

All activities in my application require a user to be logged-in to view. Users can log out from almost any activity. This is a requirement of the application. At any point if the user logs-out, I want to send the user to the Login Activity. At this…
skyler
  • 8,010
  • 15
  • 46
  • 69
221
votes
9 answers

App restarts rather than resumes

Hopefully someone can help me figure out, if not a solution, at least an explanation for a behaviour. The Problem: On some devices, pressing the launcher icon results in the current task being resumed, on others it results in the initial launch…
Graeme
  • 25,714
  • 24
  • 124
  • 186
197
votes
14 answers

How to get rid of Incremental annotation processing requested warning?

I have just started using android development and trying to use Room library. Since yesterday I am facing this warning message w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not…
Shax
  • 4,207
  • 10
  • 46
  • 62
180
votes
13 answers

java.lang.IllegalStateException: Fragment not attached to Activity

I am rarely getting this error while making an API call. java.lang.IllegalStateException: Fragment not attached to Activity I tried putting the code inside isAdded() method to check whether fragment is currently added to its activity but still i…
170
votes
8 answers

How do I prevent Android taking a screenshot when my app goes to the background?

The app I'm currently building has the requirement that the app has to prevent the OS to take a screenshot of the app when it's being pushed into the background for security reasons. This way it won't be able to see the last active screen when…
StingRay5
  • 2,388
  • 2
  • 20
  • 29
170
votes
8 answers

What is the difference between onPause() and onStop() of Android Activites?

From android doc here http://developer.android.com/reference/android/app/Activity.html, it said 'Activity comes into foreground' will call onPause(), and 'Activity is no longer visible' will call onStop(). Isn't 'Activity comes into foreground' same…
michael
  • 106,540
  • 116
  • 246
  • 346
161
votes
8 answers

One Activity and all other Fragments

I am thinking of implementing one screen with Activity and all other sreens with Fragments and managing all the fragments thru the activity. Is it a good idea? and my answer is NO but still I want to know more clearly about this thought. What are…
122
votes
5 answers

When exactly are onSaveInstanceState() and onRestoreInstanceState() called?

The following figure (from the official doc) describes the well-known lifecycle of an Android activity: On the other hand, when the activity is destroyed by the system (for example because memory needs to be reclaimed), the state of the activity is…
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
107
votes
4 answers

Android static object lifecycle

I am creating event search application, we set search criteria from one screen populate in another screen then user can edit search criteria from 3rd screen and goes to 4th screen. To achieve above task i am using static object which remember the…
d-man
  • 57,473
  • 85
  • 212
  • 296
103
votes
6 answers

What is the benefit of using Fragments in Android, rather than Views?

When developing for Android, you can set your target (or minimum) sdk to 4 (API 1.6) and add the android compatibility package (v4) to add support for Fragments. Yesterday I did this and successfully implemented Fragments to visualize data from a…
Phil
  • 35,852
  • 23
  • 123
  • 164
102
votes
16 answers

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} at…
user782104
  • 13,233
  • 55
  • 172
  • 312
100
votes
7 answers

What is the correct order of calling superclass methods in onPause, onStop and onDestroy methods? and Why?

I was just going through the Android Developer Site, refreshing on the Activity Life cycle, and in each code example, there is a comment beside the super class methods that says "Always call the superclass method first". Though this makes sense in…
Anudeep Bulla
  • 8,318
  • 4
  • 22
  • 29
97
votes
9 answers

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 related to each activity the user ends on my app, but not when the user forces stop or kills…
Darknoe
  • 1,190
  • 1
  • 9
  • 11
1
2 3
99 100