narimetisaigopi

android life cycle methods example

Jan 10th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package com.example.teachingdemoapp;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.widget.Toast;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15. printDemo("onCreate");
  16. }
  17.  
  18. @Override
  19. protected void onStart() {
  20. super.onStart();
  21. printDemo("onStart");
  22. }
  23.  
  24. @Override
  25. protected void onResume() {
  26. super.onResume();
  27. printDemo("onResume");
  28. }
  29.  
  30. @Override
  31. protected void onPause() {
  32. super.onPause();
  33. printDemo("onPause");
  34. }
  35.  
  36. @Override
  37. protected void onStop() {
  38. super.onStop();
  39. printDemo("onStop");
  40. }
  41.  
  42. @Override
  43. protected void onRestart() {
  44. super.onRestart();
  45. printDemo("onRestart");
  46. }
  47.  
  48. @Override
  49. protected void onDestroy() {
  50. super.onDestroy();
  51. printDemo("onDestroy");
  52. }
  53.  
  54.  
  55. void printDemo(String message){
  56. Log.d("MainActivity",message);
  57. Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
  58. }
  59. }
Add Comment
Please, Sign In to add comment