Giter Club home page Giter Club logo

android-lifecycle's Introduction

Complete Android Fragment & Activity Lifecycle

After struggling with trying to figure out how various pieces fit together, I've done some research and put together the complete Android Activity/Fragment lifecycle chart. This has two parallel lifecycles (activities and fragments) which are organized vertically by time. Lifecycle stages will occur in the vertical order in which they're displayed, across activities and fragments. In this way, you can see how your fragments interact with your activities.

If you see any discrepancies or errors in this diagram, please submit a pull request or contact [email protected].

Activity and Fragment Lifecycles

Vector versions suitable for printing: PDF or SVG

A Complete Android Fragment & Activity Lifecycle

Activity, Fragment and FragmentManager Lifecycle Integration

Vector versions suitable for printing PDF2 or SVG2

A Integration Of Fragments into Activities via Fragment Manager

Some Notes

This intentionally leaves off user-triggered callbacks (such as onOptionsItemSelected()), focusing on the lifecycle stages that are triggered by the system, in order to keep the diagram more focused on the parts that are hard to follow.

The canonical format of the diagram is the Dia file. It was then exported to SVG, hand-tweaked to fix font sizes, and imported into Inkscape to do an SVG, PDF, and PNG render. I hope to find a better workflow for this going forward; patches always welcome.

License

This diagram (in all its various forms and renders) is licensed under the Creative Commons BY-SA 4.0 license. If you would like it under a different Creative Commons license, please contact me and we can figure something out.

android-lifecycle's People

Contributors

xxv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-lifecycle's Issues

Add onCreateAnimation callback

Lifecycle documentation lacks this. I'm not sure if fits the "lifecycle" but this method is somehow related to lifecycle.

Amazing. Moar?

Have you tried at all to connect the two graphs? The real excitement is when you try to understand how a Fragment's lifecycle interweaves with its Activity's.

Samsung made lifecycle changes

onCreateOptionsMenu() and onResume() have their order swapped on Samsung devices, we've encountered it in Galaxy S4 and Galaxy Ace.

Can't confirm because it happened 6 months ago.

missing onActivityResult in fragment lifecycle

missing in Fragment lifecycle: onActivityResult. Maybe it's same as in Activity? Called after onStart()?

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

Update required for onResume() / onResumeFragments()

You've documented a 'wierdness' with v4 compat for onResume/onPostResume. It's worth saying that onResume() should be used for normal Activity's and onResumeFragments() when using the v4 compat library. This is only required when the application is waiting for the initial FragmentTransaction's to be completed by the FragmentManager. For instance the application wants to access a Fragment that was inflated during onCreate(). The best place for this is onResumeFragments().

See: http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html#onResumeFragments%28%29

Multi-window mode

Update the diagram with the quarks introduced with multi-window mode to the lifecycle. Such as the recommendation to have video apps handle playback play/pause in onStart/onStop instead of onResume/onPause

onPostCreate() not called as shown

The Activity diagram indicates that onPostCreate() is called regularly after onStart(). However, I am seeing that onPostCreate() seems to be called only once per onCreate(). It is not called again if the Activity calls onStart() again later.

Bug

The lifecycle of fragment seems wrong .The fragment will both re-attach and re-create if we re-enter the activity after the system kill the process.
PS: I hate some guy below with bad manner.

Lifecycle when starting another Activity

First of all, this is awesome. Spotted it in Android Weekly, and it is much more comprehensive than the lifecycle diagram in the Android docs.

It would be awesome to include the order of lifecycle events when another Activity is started. According to the docs, the order of events in a single application is well defined:

  1. Activity A's onPause() method executes.
  2. Activity B's onCreate(), onStart(), and onResume() methods execute in sequence. (Activity B now has user focus.)
  3. Then, if Activity A is no longer visible on screen, its onStop() method executes.

However, I haven't verified this myself (or seen the info reproduced anywhere else).

View Lifecycle

any chance? onFinishInflate onDraw onSaveInstanceState etc

Release tags and changelog

Can you please at tags via git tag -a "v.0.9.0" -m "Added this and that" and a CHANGELOG.md to the repository such as this.

Clarification: onCreateOptionMenu() called ones but onPrepareOptionMenu() every time

Fact:
onCreateOptionMenu() called ones but onPrepareOptionMenu() every time.

Proof:
onCreateOptionMenu() is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu).

onPrepareOptionMenu() Prepare the Screen's standard options menu to be displayed. This is called right before the menu is shown, every time it is shown

Problem:
Block diagram shows that every time onResume() called both onCreateOptionMenu() and onPrepareOptionMenu() are called. Which is not true.

Solutions:
"Called once, the first time the options menu is displayed or if menu invalidated" comment need to be added there or condition (diamond-like) block with text "first menu display or invalidated" and "yes" and "no" branches

layout issue

I believe the note about onPostResume() is cut. should read "compatibility" instead of "compat"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.