Created
June 29, 2018 01:11
-
-
Save leesc22/75b67a8b9089dbb4ebf52326461294dc to your computer and use it in GitHub Desktop.
Android Activity Lifecycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.lifecycle | |
import android.support.v7.app.AppCompatActivity | |
import android.os.Bundle | |
import android.util.Log | |
// When the Activity first time loads the events called are: | |
// onCreate(), onStart(), onResume() | |
// When click on home button, the Activity goes to the background | |
// The events called are: | |
// onPause(), onStop() | |
// Return to the Activity, the events called are: | |
// onRestart(), onStart(), onResume() | |
// When click the back button, the events called are: | |
// onPause(), onStop(), onDestroy() | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
Log.v("MainActivity", "LifeCycleEvents: onCreate") | |
} | |
override fun onStart() { | |
super.onStart() | |
Log.v("MainActivity", "LifeCycleEvents: onStart") | |
} | |
override fun onRestart() { | |
super.onRestart() | |
Log.v("MainActivity", "LifeCycleEvents: onRestart") | |
} | |
override fun onResume() { | |
super.onResume() | |
Log.v("MainActivity", "LifeCycleEvents: onResume") | |
} | |
override fun onPause() { | |
super.onPause() | |
Log.v("MainActivity", "LifeCycleEvents: onPause") | |
} | |
override fun onStop() { | |
super.onStop() | |
Log.v("MainActivity", "LifeCycleEvents: onStop") | |
} | |
override fun onDestroy() { | |
super.onDestroy() | |
Log.v("MainActivity", "LifeCycleEvents: onDestroy") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment