1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.lifecycle; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.view.View; 23 import android.widget.TextView; 24 25 import com.example.android.lifecycle.util.StatusTracker; 26 import com.example.android.lifecycle.util.Utils; 27 28 /** 29 * Example Activity to demonstrate the lifecycle callback methods. 30 */ 31 public class ActivityA extends Activity { 32 33 private String mActivityName; 34 private TextView mStatusView; 35 private TextView mStatusAllView; 36 private StatusTracker mStatusTracker = StatusTracker.getInstance(); 37 38 @Override onCreate(Bundle savedInstanceState)39 public void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 setContentView(R.layout.activity_a); 42 mActivityName = getString(R.string.activity_a); 43 mStatusView = (TextView)findViewById(R.id.status_view_a); 44 mStatusAllView = (TextView)findViewById(R.id.status_view_all_a); 45 mStatusTracker.setStatus(mActivityName, getString(R.string.on_create)); 46 Utils.printStatus(mStatusView, mStatusAllView); 47 } 48 49 @Override onStart()50 protected void onStart() { 51 super.onStart(); 52 mStatusTracker.setStatus(mActivityName, getString(R.string.on_start)); 53 Utils.printStatus(mStatusView, mStatusAllView); 54 } 55 56 @Override onRestart()57 protected void onRestart() { 58 super.onRestart(); 59 mStatusTracker.setStatus(mActivityName, getString(R.string.on_restart)); 60 Utils.printStatus(mStatusView, mStatusAllView); 61 } 62 63 @Override onResume()64 protected void onResume() { 65 super.onResume(); 66 mStatusTracker.setStatus(mActivityName, getString(R.string.on_resume)); 67 Utils.printStatus(mStatusView, mStatusAllView); 68 } 69 70 @Override onPause()71 protected void onPause() { 72 super.onPause(); 73 mStatusTracker.setStatus(mActivityName, getString(R.string.on_pause)); 74 Utils.printStatus(mStatusView, mStatusAllView); 75 } 76 77 @Override onStop()78 protected void onStop() { 79 super.onStop(); 80 mStatusTracker.setStatus(mActivityName, getString(R.string.on_stop)); 81 } 82 83 @Override onDestroy()84 protected void onDestroy() { 85 super.onDestroy(); 86 mStatusTracker.setStatus(mActivityName, getString(R.string.on_destroy)); 87 mStatusTracker.clear(); 88 } 89 startDialog(View v)90 public void startDialog(View v) { 91 Intent intent = new Intent(ActivityA.this, DialogActivity.class); 92 startActivity(intent); 93 } 94 startActivityB(View v)95 public void startActivityB(View v) { 96 Intent intent = new Intent(ActivityA.this, ActivityB.class); 97 startActivity(intent); 98 } 99 startActivityC(View v)100 public void startActivityC(View v) { 101 Intent intent = new Intent(ActivityA.this, ActivityC.class); 102 startActivity(intent); 103 } 104 finishActivityA(View v)105 public void finishActivityA(View v) { 106 ActivityA.this.finish(); 107 } 108 109 } 110