Wednesday 18 July 2018

Navigation-OnBackPressed-To-Back-To-HomePage

            Navigation-OnBackPressed-To-Back-To-HomePage

Find the code in GitHub: Go to GitHub page


1. Create a project with navigation drawer activity

Pre-added files

i) res-layout folder
activity_main.xml
app_bar_main.xml
content_main.xml
nav_header.xml

ii) java-main-folder
MainActivity.java

Monday 16 July 2018

How to work lifecycle if load Activity and call another Activity and Activity lifecycle description & Explain

How to work lifecycle if load Activity and call another Activity


                    Portrait Mode i.e (Non-rotational)


1. First, create MainActivity which has all lifecycle of Activity.

Activity lifecycle i.e.

onCreate() -> onStart() -> onResume -> onPause() -> onStop() -> onDestroyed() 
                                   ↑                                                                                                   
                                    <----------------------   onRestart()

If Activity calling the lifecycle method i.e


Activity-1 call- >                           onCreate() ->(Activity-1)                 
                                                          onStart() ->(Activity-1)
                                                          onResume() ->(Activity-1)

When user click event and call another activity-2 then lifecycle how to works and call method

Activity-1 call- >                           onPause() ->(Activity-1)                 
                                                                 
Activity-2 call- >                           onCreate() ->(Activity-2)                 
                                                          onStart() ->(Activity-2)
                                                          onResume() ->(Activity-2)
                                                  ↓
Activity-1 call- >                           onStop() ->(Activity-1)                 
                                                                 

When the user clicks onBackPressed then lifecycle how to works and call method

Activity-2 call- >                           onPause() ->(Activity-2)                 
                                                                 
Activity-1 call- >                           onRestart() ->(Activity-1)                 
                                                          onStart() ->(Activity-1)
                                                          onResume() ->(Activity-1)
                                                  ↓
Activity-2 call- >                           onStop() ->(Activity-2)      
                                                          onDestroy() ->(Activity-2)     
                                                                 

When the press Home Button then lifecycle how to works and call method

Activity-1 call- >                           onPause() ->(Activity-1)                 
                                                          onStop() ->(Activity-1)

When the reOpen the app to background then lifecycle how to works and call method

Activity-1 call- >                           onRestart() ->(Activity-1)                 
                                                          onStart() ->(Activity-1)
                                                          onResume() ->(Activity-1)

When the close the app or remove the app to background then lifecycle how to works and call method

Activity-1 call- >                           onPause() ->(Activity-1)                 
                                                          onStop() ->(Activity-1)            
                                                          onDestroy() ->(Activity-1)


*******************************************************************************
                                                         Thank you

How to work lifecycle if load Fragment and Activity and load another Activity and Activity and Fragment lifecycle description & Explain

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)
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)

When the user clicks onBackPressed then lifecycle how to works and call method

New Activity 2 method call ->                                     
                                                         onPause() ->(Activity-2)
then Activity-1 method call->                   ↓
                                                         onRestart() ->(Activity-1)
then Fragment method call->                  ↓
                                                         onStart() ->(Fragment)
then Activity-1 method call->                   ↓
                                                         onStart() ->(Activity-1)
                                                         onResume() ->(Activity-1)
then Fragment method ->                                     
                                                         onResume() ->(Fragment)
then Activity-2 method ->                                    
                                                         onStop() ->(Activity-2)
                                                         onDestroy() ->(Activity-2)

*******************************************************************************
                                                         Thank you

How to work lifecycle if load Fragment and Activity and Replace another fragment and Activity and Fragment lifecycle description & Explain

How to work lifecycle if load Fragment and Activity and Replace another fragment 

                          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 fragment-2 then lifecycle how to works and call method

another Fragment-2 call ->               
                                                         onAttach() ->(Fragment-2)
                                                         onCreate() ->(Fragment-2)
then Fragment-1 method ->              
                                                        onPause() ->(Fragment-1)
                                                        onStop() ->(Fragment-1)
                                                        onDestroyView() ->(Fragment-1)
                                                        onDestroyed() ->(Fragment-1)  
                                                        onDettach() ->(Fragment-1)    
then Fragment-2 method ->                         
                                                        onCreateView() ->(Fragment-2)
                                                        onActivityCreated() ->(Fragment-2)
                                                        onStart() ->(Fragment-2)
                                                        onResume() ->(Fragment-2)

When the user clicks before fragment-1 then lifecycle how to works and call method

 Fragment-1 call ->                           
                                                         onAttach() ->(Fragment-2)
                                                         onCreate() ->(Fragment-2)
then Fragment-2 method ->              
                                                        onPause() ->(Fragment-1)
                                                        onStop() ->(Fragment-1)
                                                        onDestroyView() ->(Fragment-1)
                                                        onDestroyed() ->(Fragment-1)  
                                                        onDettach() ->(Fragment-1)    
then Fragment-1 method ->               
                                                        onCreateView() ->(Fragment-2)
                                                        onActivityCreated() ->(Fragment-2)
                                                        onStart() ->(Fragment-2)
                                                        onResume() ->(Fragment-2)


*******************************************************************************
                                                         Thank you