How to work lifecycle if load Fragment and Activity and load another Activity
Portrait Mode i.e (Non-rotational)
1. First, create MainActivity and one Fragment which has all lifecycle include in Fragment and Activity.
Activity lifecycle i.e.
onCreate() -> onStart() -> onResume -> onPause() -> onStop() -> onDestroyed()
↑ ↓
<---------------------- onRestart()
Fragment lifecycle i.e.
onAttach() -> onCreate() -> onCreateView() -> onActivityCreated() -> onStart() -> onResume -> onPause() -> onStop() ->
↑ ↑<----------------------------------------------↓
onDestroyed() -> onDestroyedView() -> onDetach()
If Activity and Fragment load at the same time when calling the lifecycle method i.e
Activity call- >
onCreate() ->(Activity)
then call Fragment method -> ↓
onAttach() ->(Fragment)
onCreate() -> (Fragment)
onCreateView() ->(Fragment)
onActivityCreated() ->(Fragment)
onStart() ->(Fragment)
then Activity call -> ↓
onStart() ->(Activity)
onResume() ->(Activity)
then call Fragment method -> ↓
onResume() ->(Fragment)
When user click another activity-2 then lifecycle how to works and call method
Fragment method call -> ↓onPause() ->(Fragment)
then Activity-1 method call-> ↓
onPause() ->(Activity-1)
onPause() ->(Activity-1)
then Activity-2 method call-> ↓
onCreate() ->(Activity-2)
onStart() ->(Activity-2)
onResume() ->(Activity-2)
then Fragment method -> ↓
onStop() ->(Fragment)
then Activity-1 method -> ↓
onStop() ->(Activity-1)
*******************************************************************************
Thank you
onResume() ->(Activity-2)
then Fragment method -> ↓
onStop() ->(Fragment)
then Activity-1 method -> ↓
onStop() ->(Activity-1)
When the user clicks onBackPressed then lifecycle how to works and call method
New Activity 2 method call -> ↓
onPause() ->(Activity-2)
onPause() ->(Activity-2)
then Activity-1 method call-> ↓
onRestart() ->(Activity-1)
onRestart() ->(Activity-1)
then Fragment method call-> ↓
onStart() ->(Fragment)
then Activity-1 method call-> ↓
onStart() ->(Activity-1)
onStart() ->(Activity-1)
onResume() ->(Activity-1)
then Fragment method -> ↓
onResume() ->(Fragment)
then Activity-2 method -> ↓
onStop() ->(Activity-2)
then Fragment method -> ↓
onResume() ->(Fragment)
then Activity-2 method -> ↓
onStop() ->(Activity-2)
onDestroy() ->(Activity-2)
Thank you
No comments:
Post a Comment