Showing posts with label Activity. Show all posts
Showing posts with label Activity. Show all posts

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

Monday, 16 July 2018

How to work lifecycle if load Fragment and Activity and Press the home button and close the application and Activity and Fragment lifecycle description & Explain

How to work lifecycle if load Fragment and Activity and Press the home button and close the application

                          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 press home button & run in background then lifecycle how to works and call method

 Fragment call ->                              ↓
                                                         onPause() ->(Fragment)
then call Activity method ->            ↓
                                                        onPause() ->(Activity)
 Fragment call ->                              ↓
                                                         onStop() ->(Fragment)
then call Activity method ->            ↓
                                                        onStop() ->(Activity)


When user ReOpen application then lifecycle how to works and call method

Activity method ->                          ↓
                                                        onRestart() ->(Activity)
 Fragment call ->                              ↓
                                                         onStart() ->(Fragment)
then Activity call ->                         ↓
                                                         onStart() ->(Activity)
                                                         onResume() ->(Activity)
then call Fragment method ->          ↓
                                                        onResume() ->(Fragment)                          



When user close application then lifecycle how to works and call method

 Fragment call ->                              ↓
                                                         onPause() ->(Fragment)
then Activity call ->                         ↓
                                                         onPause() ->(Activity)
then call Fragment method ->          ↓
                                                        onStop() ->(Fragment)                          
then Activity call ->                         ↓
                                                         onStop() ->(Activity)
then call Fragment method ->          ↓
                                                        onDestroyView() ->(Fragment)
                                                        onDestroyed() ->(Fragment)  
                                                        onDettach() ->(Fragment)    
then Activity call ->                         ↓
                                                         onDestroyed() ->(Activity)

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