-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivityA.java
More file actions
132 lines (111 loc) · 4.31 KB
/
ActivityA.java
File metadata and controls
132 lines (111 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.lifecycle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.android.lifecycle.util.StatusTracker;
import com.example.android.lifecycle.util.Utils;
/**
* Example Activity to demonstrate the lifecycle callback methods.
*/
public class ActivityA extends Activity {
private String mActivityName;
private TextView mStatusView;
private TextView mStatusAllView;
private StatusTracker mStatusTracker = StatusTracker.getInstance();
public static int restart_counter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//check whether we are restoring a previously destroyed instance
if(savedInstanceState != null){
//restore the reset counter from saved state
restart_counter = savedInstanceState.getInt("restart_counter");
}else{
System.out.print("Cannot restore the state of your activity");
}
setContentView(R.layout.activity_a);
mActivityName = getString(R.string.activity_a);
TextView counterTextView = (TextView)findViewById(R.id.thread_counter);
restart_counter = 0;
counterTextView.setText("Reset Count: "+restart_counter);
mStatusTracker.setStatus(mActivityName, getString(R.string.on_create));
}
@Override
protected void onStart() {
super.onStart();
mStatusTracker.setStatus(mActivityName, getString(R.string.on_start));
Utils.printStatus(mStatusView, mStatusAllView);
}
@Override
protected void onRestart() {
super.onRestart();
mStatusTracker.setStatus(mActivityName, getString(R.string.on_restart));
Utils.printStatus(mStatusView, mStatusAllView);
restart_counter = restart_counter + 1;
TextView counterTextView = (TextView)findViewById(R.id.thread_counter);
counterTextView.setText("Reset Count: "+restart_counter);
}
@Override
protected void onResume() {
super.onResume();
mStatusTracker.setStatus(mActivityName, getString(R.string.on_resume));
Utils.printStatus(mStatusView, mStatusAllView);
}
@Override
protected void onPause() {
super.onPause();
mStatusTracker.setStatus(mActivityName, getString(R.string.on_pause));
Utils.printStatus(mStatusView, mStatusAllView);
}
@Override
protected void onStop() {
super.onStop();
mStatusTracker.setStatus(mActivityName, getString(R.string.on_stop));
}
@Override
protected void onDestroy() {
super.onDestroy();
mStatusTracker.setStatus(mActivityName, getString(R.string.on_destroy));
mStatusTracker.clear();
}
//To save the state of the activity before getting killed by OS let's say
@Override
public void onSaveInstanceState(Bundle savedInstanceState){
//Save the activity's current reset counter
savedInstanceState.putInt("restart_counter", restart_counter);
//Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}
public void startDialog(View v) {
Intent intent = new Intent(ActivityA.this, DialogActivity.class);
startActivity(intent);
}
public void startActivityB(View v) {
Intent intent = new Intent(ActivityA.this, ActivityB.class);
startActivity(intent);
}
public void startActivityC(View v) {
Intent intent = new Intent(ActivityA.this, ActivityC.class);
startActivity(intent);
}
public void finishActivityA(View v) {
ActivityA.this.finish();
}
}