In which we added a new view to the GeoQuiz to show stats instead of showing them on the original MainActivity.

MainActivity.kt
package edu.ius.c490.geoquiz

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast

const val REQUEST_RESET = 0

class MainActivity : AppCompatActivity() {

    private lateinit var trueButton: Button
    private lateinit var falseButton: Button

    private val questionBank = listOf(
        Question(R.string.question_thailand, true),
        Question(R.string.question_africa, false),
        Question(R.string.question_americas, true),
        Question(R.string.question_mideast, false),
        Question(R.string.question_ocean, true)
    )

    private var currentIndex = 0
    private lateinit var nextButton: Button
    lateinit var questionView: TextView

    private val statsButton: Button by lazy { findViewById<Button>(R.id.stats_button) }

    private var nCorrect: Int = 0
    private var nIncorrect: Int = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        trueButton = findViewById(R.id.true_button)
        falseButton = findViewById(R.id.false_button)

        nextButton = findViewById(R.id.next_button)
        questionView = findViewById(R.id.question_view)

        val questionTextResId = questionBank[currentIndex].textResId
        questionView.setText(questionTextResId)

        nextButton.setOnClickListener {
            currentIndex = (currentIndex + 1) % questionBank.size
            setQuestion()
        }

        trueButton.setOnClickListener {
            checkAnswer(true)
        }

        falseButton.setOnClickListener {
            checkAnswer(false)
        }

        statsButton.setOnClickListener {
            val intent = StatsActivity.createIntent(this@MainActivity, nCorrect, nIncorrect)
            startActivityForResult(intent, REQUEST_RESET)
        }
    }

    fun checkAnswer(userAnswer: Boolean) {
        if (userAnswer == questionBank[currentIndex].answer) {
            Toast.makeText(this@MainActivity, "Correct", Toast.LENGTH_SHORT).show()
            nCorrect++
        } else {
            Toast.makeText(this@MainActivity, "Incorrect", Toast.LENGTH_SHORT).show()
            nIncorrect++
        }
    }

    private fun setQuestion() {
        val questionTextResId = questionBank[currentIndex].textResId
        questionView.setText(questionTextResId)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (resultCode != Activity.RESULT_OK)
            return

        if (requestCode == REQUEST_RESET) {
            val reset = data?.getBooleanExtra(EXTRA_RESET, false)
            if (reset!!) {
                nCorrect = 0
                nIncorrect = 0
                currentIndex = 0
                setQuestion()
            }
        }


    }
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:text="@string/question_thailand"
            android:id="@+id/question_view"
            android:padding="24dp"
            />
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/true_button"
                android:text="@string/true_button" />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/false_button"
                android:text="@string/false_button" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/next_button"
                android:text="@string/next_button" />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/stats_button"
                android:text="@string/stats_button_text"/>
        </LinearLayout>
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
StatsActivity.kt
package edu.ius.c490.geoquiz

import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView

const val EXTRA_N_CORRECT = "edu.ius.c490.geoquiz.StatsActivity.nCorrect"
const val EXTRA_N_INCORRECT = "edu.ius.c490.geoquiz.StatsActivity.nIncorrect"
const val EXTRA_RESET = "edu.ius.c490.geoquiz.StatsActivity.reset"

class StatsActivity : AppCompatActivity() {

    private val resetButton: Button by lazy { findViewById<Button>(R.id.reset_button) }
    private val dismissButton: Button by lazy { findViewById<Button>(R.id.dismiss_button) }
    private val statsText: TextView by lazy { findViewById<TextView>(R.id.stats_text) }

    private var nCorrect: Int = 0
    private var nIncorrect: Int = 0

    companion object {
        fun createIntent(packageContext: Context, nCorrect: Int, nIncorrect: Int): Intent {
            return Intent(packageContext, StatsActivity::class.java).apply {
                putExtra(EXTRA_N_CORRECT, nCorrect)
                putExtra(EXTRA_N_INCORRECT, nIncorrect)
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_stats)

        dismissButton.setOnClickListener {
            setReturnValue(false)
            finish()
        }

        resetButton.setOnClickListener {
            setReturnValue(true)
            finish()
        }

        nCorrect = intent.getIntExtra(EXTRA_N_CORRECT, 0)
        nIncorrect = intent.getIntExtra(EXTRA_N_INCORRECT, 0)

        val total = nCorrect + nIncorrect

        statsText.text = "You currently have answered $nCorrect out of $total questions right."
    }

    private fun setReturnValue(isReset: Boolean) {
        val data = Intent().apply {
            putExtra(EXTRA_RESET, isReset)
        }
        setResult(Activity.RESULT_OK, data)
    }
}
activity_stats.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".StatsActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="12dp"
            android:id="@+id/stats_text"
            android:text="@string/stats_text_default" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/dismiss_button"
                android:text="@string/dismiss_button"/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/reset_button"
                android:text="@string/reset_button" />
        </LinearLayout>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>