../android-components-note

Four main components in Android note

Activity, Service, BroadcastRecevier, ContentProvider

Activity lifecycle:


ActivityLaunched…
    onCreate();
    onStart();
    onResume();
    ActivityRunning…
    If activity not in foreground (but still visible):
        onPause();
        If activity is back to foreground:
            goto -> onResume();
        If activity is no longer  visible:
            onStop();
            If user navigates back to the activity:
                onRestart();
                goto -> onStart();
            If activity is killed by system due to memory allocation and now user navigates back to the activity:
                goto -> onCreate();
            onDestroy();
ActivityShutDown…



image1

Fragment lifecycle:

FragmentAdded…
    onAttach();
    onCreate();
    onCreateView();		
    onActivityCreated();
    onStart();
    onResume();
    FragmentActive…
    If fragment is added to back stack || user navigates backward || fragment is removed/replaced:
        onPause();
        onStop();
        onDestroyView();
        If fragment returns from back stack:
            goto -> onCreateView();
        onDestroy();
        onDetach();
FragmentDestroyed…


image2

/note/ /components/ /Android/