My lifecycle codes on android studio not compiling : For each callback events (onCreate(), onStart()... ), record what callback event was triggered in the log(use Log.d); the message that is written to log should be defined in “strings.xml” and getResources.getString() should be used to retrieve the message 

Implement onSaveInstanceState and onRestoreInstanceState – to track the number of times onSaveInstanceState is being called, in onRestoreInstanceState, print the value to the log file 

Tag for “Log” statement should also be defined in strings.xml and set using getResources.getString()












    package com.csci235labs.rob_lifecycles;

    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.util.Log;

    public class MainActivity extends AppCompatActivity {

    String TAG = getResources().getString(R.string.app_name); //Logcat tag
    String ActivityState;
    int instanceTimes; //number of times instance is called
    String Act_keys;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //recover instance state
        if(savedInstanceState!=null)
        {
            ActivityState = savedInstanceState.getString(Act_keys);
        }
        else
        {
            instanceTimes=0;
            Act_keys="";
        }

        setContentView(R.layout.activity_main);


    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        instanceTimes++;
        ActivityState=String.valueOf(instanceTimes);

        outState.putString(Act_keys,ActivityState);

        super.onSaveInstanceState(outState);
    }


    @Override
    protected void onStart() {
        super.onStart();
        //logs event message
        String eventMessage=getResources().getString(R.string.on_start_str);
        Log.d(TAG,eventMessage);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //logs event message
        String eventMessage=getResources().getString(R.string.on_resume_str);
        Log.d(TAG,eventMessage);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //logs event message
        String eventMessage=getResources().getString(R.string.on_pause_str);
        Log.d(TAG,eventMessage);
    }

    @Override
    protected void onStop() {
        super.onStop();
        //logs event message
        String eventMessage=getResources().getString(R.string.on_stop_str);
        Log.d(TAG,eventMessage);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //logs event message
        String eventMessage=getResources().getString(R.string.on_destroy_str);
        Log.d(TAG,eventMessage);
    }
}

-----------------------------------------------------------
XML Files

