Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmsc436-student
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrej Rasevic
cmsc436-student
Commits
11df409a
Commit
11df409a
authored
7 years ago
by
Andrej Rasevic
Browse files
Options
Downloads
Patches
Plain Diff
stripped away implementation and some hints
parent
eb4a5f0e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/course/labs/activitylab/ActivityOne.java
+15
-45
15 additions, 45 deletions
app/src/main/java/course/labs/activitylab/ActivityOne.java
app/src/main/java/course/labs/activitylab/ActivityTwo.java
+17
-46
17 additions, 46 deletions
app/src/main/java/course/labs/activitylab/ActivityTwo.java
with
32 additions
and
91 deletions
app/src/main/java/course/labs/activitylab/ActivityOne.java
+
15
−
45
View file @
11df409a
...
@@ -24,19 +24,10 @@ public class ActivityOne extends Activity {
...
@@ -24,19 +24,10 @@ public class ActivityOne extends Activity {
// TODO:
// TODO:
// Create counter variables for onCreate(), onRestart(), onStart() and
// Create counter variables for onCreate(), onRestart(), onStart() and
// onResume()
// onResume()
// You will need to increment these variables' values when their
// corresponding lifecycle methods get called
private
int
mCreate
=
0
;
private
int
mRestart
=
0
;
private
int
mStart
=
0
;
private
int
mResume
=
0
;
// TODO: Create variables for each of the TextViews
// TODO: Create variables for each of the TextViews
private
TextView
mTvCreate
;
private
TextView
mTvRestart
;
private
TextView
mTvStart
;
private
TextView
mTvResume
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -47,10 +38,6 @@ public class ActivityOne extends Activity {
...
@@ -47,10 +38,6 @@ public class ActivityOne extends Activity {
// Hint: Access the TextView by calling Activity's findViewById()
// Hint: Access the TextView by calling Activity's findViewById()
// textView1 = (TextView) findViewById(R.id.textView1);
// textView1 = (TextView) findViewById(R.id.textView1);
mTvCreate
=
findViewById
(
R
.
id
.
create
);
mTvRestart
=
findViewById
(
R
.
id
.
restart
);
mTvStart
=
findViewById
(
R
.
id
.
start
);
mTvResume
=
findViewById
(
R
.
id
.
resume
);
Button
launchActivityTwoButton
=
findViewById
(
R
.
id
.
bLaunchActivityTwo
);
Button
launchActivityTwoButton
=
findViewById
(
R
.
id
.
bLaunchActivityTwo
);
launchActivityTwoButton
.
setOnClickListener
(
new
OnClickListener
()
{
launchActivityTwoButton
.
setOnClickListener
(
new
OnClickListener
()
{
...
@@ -62,10 +49,8 @@ public class ActivityOne extends Activity {
...
@@ -62,10 +49,8 @@ public class ActivityOne extends Activity {
// Hint: use Context's startActivity() method
// Hint: use Context's startActivity() method
// Create an intent stating which Activity you would like to start
// Create an intent stating which Activity you would like to start
Intent
intent
=
new
Intent
(
ActivityOne
.
this
,
ActivityTwo
.
class
);
// Launch the Activity using the intent
// Launch the Activity using the intent
startActivity
(
intent
);
}
}
});
});
...
@@ -75,12 +60,6 @@ public class ActivityOne extends Activity {
...
@@ -75,12 +60,6 @@ public class ActivityOne extends Activity {
// TODO:
// TODO:
// Restore value of counters from saved state
// Restore value of counters from saved state
// Only need 4 lines of code, one for every count variable
mCreate
=
savedInstanceState
.
getInt
(
CREATE_KEY
);
mStart
=
savedInstanceState
.
getInt
(
START_KEY
);
mResume
=
savedInstanceState
.
getInt
(
RESUME_KEY
);
mRestart
=
savedInstanceState
.
getInt
(
RESTART_KEY
);
}
}
...
@@ -90,8 +69,7 @@ public class ActivityOne extends Activity {
...
@@ -90,8 +69,7 @@ public class ActivityOne extends Activity {
// TODO:
// TODO:
// Update the appropriate count variable
// Update the appropriate count variable
// Update the user interface via the displayCounts() method
// Update the user interface via the displayCounts() method
mCreate
++;
displayCounts
();
}
}
...
@@ -107,8 +85,7 @@ public class ActivityOne extends Activity {
...
@@ -107,8 +85,7 @@ public class ActivityOne extends Activity {
// TODO:
// TODO:
// Update the appropriate count variable
// Update the appropriate count variable
// Update the user interface
// Update the user interface
mStart
++;
displayCounts
();
}
}
@Override
@Override
...
@@ -121,69 +98,62 @@ public class ActivityOne extends Activity {
...
@@ -121,69 +98,62 @@ public class ActivityOne extends Activity {
// TODO:
// TODO:
// Update the appropriate count variable
// Update the appropriate count variable
// Update the user interface
// Update the user interface
mResume
++;
displayCounts
();
}
}
@Override
@Override
public
void
onPause
()
{
public
void
onPause
()
{
super
.
onPause
();
super
.
onPause
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onPause() method"
);
// Follow the previous 2 examples provided
}
}
@Override
@Override
public
void
onStop
()
{
public
void
onStop
()
{
super
.
onStop
();
super
.
onStop
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onStop() method"
);
// Follow the previous 2 examples provided
}
}
@Override
@Override
public
void
onRestart
()
{
public
void
onRestart
()
{
super
.
onRestart
();
super
.
onRestart
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onRestart() method"
);
// Follow the previous 2 examples provided
// TODO:
// TODO:
// Update the appropriate count variable
// Update the appropriate count variable
// Update the user interface
// Update the user interface
mRestart
++;
displayCounts
();
}
}
@Override
@Override
public
void
onDestroy
()
{
public
void
onDestroy
()
{
super
.
onDestroy
();
super
.
onDestroy
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onDestroy() method"
);
// Follow the previous 2 examples provided
}
}
@Override
@Override
public
void
onSaveInstanceState
(
Bundle
savedInstanceState
)
{
public
void
onSaveInstanceState
(
Bundle
savedInstanceState
)
{
// TODO:
// TODO:
// Save state information with a collection of key-value pairs
// Save state information with a collection of key-value pairs
// 4 lines of code, one for every count variable
savedInstanceState
.
putInt
(
CREATE_KEY
,
mCreate
);
savedInstanceState
.
putInt
(
START_KEY
,
mStart
);
savedInstanceState
.
putInt
(
RESUME_KEY
,
mResume
);
savedInstanceState
.
putInt
(
RESTART_KEY
,
mRestart
);
}
}
// Updates the displayed counters
// Updates the displayed counters
private
void
displayCounts
()
{
private
void
displayCounts
()
{
mTvCreate
.
setText
(
"onCreate() calls: "
+
mCreate
);
// TODO:
mTvStart
.
setText
(
"onStart() calls: "
+
mStart
);
// Update the user interface via the 4 counter variables
mTvResume
.
setText
(
"onResume() calls: "
+
mResume
);
mTvRestart
.
setText
(
"onRestart() calls: "
+
mRestart
);
}
}
}
}
This diff is collapsed.
Click to expand it.
app/src/main/java/course/labs/activitylab/ActivityTwo.java
+
17
−
46
View file @
11df409a
...
@@ -26,16 +26,8 @@ public class ActivityTwo extends Activity {
...
@@ -26,16 +26,8 @@ public class ActivityTwo extends Activity {
// You will need to increment these variables' values when their
// You will need to increment these variables' values when their
// corresponding lifecycle methods get called
// corresponding lifecycle methods get called
private
int
mCreate
=
0
;
private
int
mRestart
=
0
;
private
int
mStart
=
0
;
private
int
mResume
=
0
;
// TODO: Create variables for each of the TextViews
// TODO: Create variables for each of the TextViews
private
TextView
mTvCreate
;
private
TextView
mTvRestart
;
private
TextView
mTvStart
;
private
TextView
mTvResume
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -46,10 +38,6 @@ public class ActivityTwo extends Activity {
...
@@ -46,10 +38,6 @@ public class ActivityTwo extends Activity {
// Hint: Access the TextView by calling Activity's findViewById()
// Hint: Access the TextView by calling Activity's findViewById()
// textView1 = (TextView) findViewById(R.id.textView1);
// textView1 = (TextView) findViewById(R.id.textView1);
mTvCreate
=
findViewById
(
R
.
id
.
create
);
mTvRestart
=
findViewById
(
R
.
id
.
restart
);
mTvStart
=
findViewById
(
R
.
id
.
start
);
mTvResume
=
findViewById
(
R
.
id
.
resume
);
Button
closeButton
=
findViewById
(
R
.
id
.
bClose
);
Button
closeButton
=
findViewById
(
R
.
id
.
bClose
);
closeButton
.
setOnClickListener
(
new
OnClickListener
()
{
closeButton
.
setOnClickListener
(
new
OnClickListener
()
{
...
@@ -59,9 +47,8 @@ public class ActivityTwo extends Activity {
...
@@ -59,9 +47,8 @@ public class ActivityTwo extends Activity {
// TODO:
// TODO:
// This function closes Activity Two
// This function closes Activity Two
// Hint: use Context's finish() method
finish
();
}
}
});
});
...
@@ -71,12 +58,6 @@ public class ActivityTwo extends Activity {
...
@@ -71,12 +58,6 @@ public class ActivityTwo extends Activity {
// TODO:
// TODO:
// Restore value of counters from saved state
// Restore value of counters from saved state
// Only need 4 lines of code, one for every count variable
mCreate
=
savedInstanceState
.
getInt
(
CREATE_KEY
);
mStart
=
savedInstanceState
.
getInt
(
START_KEY
);
mResume
=
savedInstanceState
.
getInt
(
RESUME_KEY
);
mRestart
=
savedInstanceState
.
getInt
(
RESTART_KEY
);
}
}
...
@@ -86,10 +67,6 @@ public class ActivityTwo extends Activity {
...
@@ -86,10 +67,6 @@ public class ActivityTwo extends Activity {
// TODO:
// TODO:
// Update the appropriate count variable
// Update the appropriate count variable
// Update the user interface via the displayCounts() method
mCreate
++;
displayCounts
();
}
}
...
@@ -105,60 +82,60 @@ public class ActivityTwo extends Activity {
...
@@ -105,60 +82,60 @@ public class ActivityTwo extends Activity {
// TODO:
// TODO:
// Update the appropriate count variable
// Update the appropriate count variable
// Update the user interface
// Update the user interface
mStart
++;
displayCounts
();
}
}
@Override
@Override
public
void
onResume
()
{
public
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onResume() method"
);
// Follow the previous 2 examples provided
// TODO:
// TODO:
// Update the appropriate count variable
// Update the appropriate count variable
// Update the user interface
mResume
++;
displayCounts
();
}
}
@Override
@Override
public
void
onPause
()
{
public
void
onPause
()
{
super
.
onPause
();
super
.
onPause
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onPause() method"
);
// Follow the previous 2 examples provided
}
}
@Override
@Override
public
void
onStop
()
{
public
void
onStop
()
{
super
.
onStop
();
super
.
onStop
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onStop() method"
);
// Follow the previous 2 examples provided
}
}
@Override
@Override
public
void
onRestart
()
{
public
void
onRestart
()
{
super
.
onRestart
();
super
.
onRestart
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onRestart() method"
);
// Follow the previous 2 examples provided
// TODO:
// TODO:
// Update the appropriate count variable
// Update the appropriate count variable
// Update the user interface
mRestart
++;
displayCounts
();
}
}
@Override
@Override
public
void
onDestroy
()
{
public
void
onDestroy
()
{
super
.
onDestroy
();
super
.
onDestroy
();
// TODO:
// Emit LogCat message
// Emit LogCat message
Log
.
i
(
TAG
,
"Entered the onDestroy() method"
);
// Follow the previous 2 examples provided
}
}
@Override
@Override
...
@@ -168,20 +145,14 @@ public class ActivityTwo extends Activity {
...
@@ -168,20 +145,14 @@ public class ActivityTwo extends Activity {
// Save counter state information with a collection of key-value pairs
// Save counter state information with a collection of key-value pairs
// 4 lines of code, one for every count variable
// 4 lines of code, one for every count variable
savedInstanceState
.
putInt
(
CREATE_KEY
,
mCreate
);
savedInstanceState
.
putInt
(
START_KEY
,
mStart
);
savedInstanceState
.
putInt
(
RESUME_KEY
,
mResume
);
savedInstanceState
.
putInt
(
RESTART_KEY
,
mRestart
);
}
}
// Updates the displayed counters
// Updates the displayed counters
private
void
displayCounts
()
{
private
void
displayCounts
()
{
mTvCreate
.
setText
(
"onCreate() calls: "
+
mCreate
);
// TODO:
mTvStart
.
setText
(
"onStart() calls: "
+
mStart
);
// Update the user interface with the 4 counter variables
mTvResume
.
setText
(
"onResume() calls: "
+
mResume
);
mTvRestart
.
setText
(
"onRestart() calls: "
+
mRestart
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment