CS计算机代考程序代写 15/06/2021 Week 3: Workshop Quiz: Attempt review

15/06/2021 Week 3: Workshop Quiz: Attempt review
FIT2081 Mobile application development – S1 2021
Dashboard / My units / FIT2081_S1_2021 / Assessments / Week 3: Workshop Quiz
Started on Monday, 15 March 2021, 9:10 PM
State Finished
Completed on Monday, 15 March 2021, 10:49 PM
Time taken 1 hour 39 mins
Grade 8.96 out of 10.00 (90%) Print friendly format
Question 1
Complete
Mark 8.96 out of 10.00
Question 1
a) Suppose you have an activity with an instance variable (class level) of type integer called ‘counter’. Your task is to save and restore the value of ‘counter’ each time the activity changes its orientation as well as the views data. Implement the required code.
public class MainActivity extends Activity { private int counter ;
@Override
protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
}
Button btnCount = findViewById (R.id.button); btnCount.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View v) { getCount ();
} });
}
private void getCount () {
++ count;
Toast.makeText (MainActivity.this, “Our count is” + count, Toast.LENGTH_SHORT) .show ();

}
https://lms.monash.edu/mod/quiz/review.php?attempt=18693572&cmid=8331149 1/4

15/06/2021 Week 3: Workshop Quiz: Attempt review
}
@ Override
protected void onRestoreInstanceState (Bundle savedInstanceState) { super.onRestoreInstanceState (savedInstanceState);
count = savedInstanceState.getInt (“Count”);
}
@Override
protected void onSaveInstanceState (Bundle outState) {
super.onSaveInstanceState (outState); outState.putInt (“Count”, count);
}
Comment:
(Q1=100% Q2=75% Q3=88% )
Question 2 Complete Not graded
Question 2
a) What is the effect of implementing onBackPressed() and calling super.onBackPressed()?
Based on the event that was consumed the BackPress events return true or false using Boolean. For example:
oveuide for on BackPressed() : Boolean {
{
return true
}
return false
}
Calling super.On BackPressed()
It defines back navigation or back button that is pressed. Each call backs that are registered via add callBack are evaluated when calling super.OnBackPressed().
Question 3 Complete Not graded
Question 3
b) Briefly explain the scenarios where the following callback methods do not get invoked during Activity lifecycle.
1. onSaveInstanceSate() 
https://lms.monash.edu/mod/quiz/review.php?attempt=18693572&cmid=8331149 2/4

15/06/2021 Week 3: Workshop Quiz: Attempt review
2. onRestoreInstaceState()
3. onDestroy()
1. Not called if the user indicates they are done with the Activity.
2. Not called if the Bundle is not non-null.
3. If kill the activity by swiping out from the background, onDestroy() method is not getting called.
Question 4 Complete Not graded
Question 4
Write a piece of code that stores the following keyvalue pairs asynchrony in a shared preferences file named “activity.file” i. unit:”FIT2081” ii. studentsCount: 510
public class MainActivity extends APPCompatActivity {
EditText etunit;
EditText etstudentCount; Buttoon btnShow; SharedPreferences userInfo;
public void SaveInfo( ){
SharePreferences.Editor edit = userInfo.edit( ); edit.putString(“unit”,”FIT2081″); edit.putString(“studentsCount”,”510″); edit.apply( );
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
userInfo = getsharedPreferences(“activity.file”, MODE_PRIVATE);
etunit = findviewById(R.id.etunit);
etnShow = findviewById(R.id.btnShow); etstudentCount = findviewById(R.id. etstudentCount);
btnShow.setOnClickListener(new view.OnClickLisetener( ) { @Override

https://lms.monash.edu/mod/quiz/review.php?attempt=18693572&cmid=8331149 3/4

15/06/2021 Week 3: Workshop Quiz: Attempt review

public void onclick(view v ){ saveInfo( );
} });
} }
Question 5 Not answered Not graded
Question 5
◄ Week 2: Workshop Quiz
Jump to…
Week 4: Workshop Quiz ►
https://lms.monash.edu/mod/quiz/review.php?attempt=18693572&cmid=8331149 4/4