Friday 11 January 2019

Android YouTube API Tutorial Using Kotlin

Android YouTube API Tutorial Using Kotlin

Play your video with Youtube URL in YoutubePlayer.

Enter your youtube URL or youtube video key and play your youtube video and handle with Play, Pause and FullScreen Button


Step 1: Include a jar file in your project

Step 2: Copy the jar file from the libs folder to the libs folder of your project.

Step 3: Click right click on a jar file and bottom show Add as a library

Step 4: Write code for Android YouTube Player API
 
Click here to check out android Kotlin source code. I provide the GitHub link which has all source code and you can easily access all code.


Step 5: Download the source Code from Github to above link

Step 6: Android YouTube API example work you need to specify your developer key. In the above example first, the onCreate method is called, in this method, YouTubePlayerView is initialized by YouTubePlayerView.initialize() method. Further, if the initialization is successful, onInitializationSuccess() method is called. In this method, one can specify the video that needs to be played.


THANK YOU

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