• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ActivityB 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_b);
42         mActivityName = getString(R.string.activity_b_label);
43         mStatusView = (TextView)findViewById(R.id.status_view_b);
44         mStatusAllView = (TextView)findViewById(R.id.status_view_all_b);
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     }
88 
startDialog(View v)89     public void startDialog(View v) {
90         Intent intent = new Intent(ActivityB.this, DialogActivity.class);
91         startActivity(intent);
92     }
93 
startActivityA(View v)94     public void startActivityA(View v) {
95         Intent intent = new Intent(ActivityB.this, ActivityA.class);
96         startActivity(intent);
97     }
98 
startActivityC(View v)99     public void startActivityC(View v) {
100         Intent intent = new Intent(ActivityB.this, ActivityC.class);
101         startActivity(intent);
102     }
103 
finishActivityB(View v)104     public void finishActivityB(View v) {
105         ActivityB.this.finish();
106     }
107 }
108