1

The main goal is to give you practice determining what methods are called during the lifecycle of your app. You must do each task and record which methods were called and in what order. The following methods should be overwritten so you can determine which ones are being called and when:

• onCreate

• onStart

• onResume

• onPause

• onStop

• onRestart

• onDestroy

• onSaveInstanceState

• onRestoreInstanceState

• onConfigurationChanged

package com.example.martij62.myapplication;

import android.content.res.Configuration;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {

@Override
protected void  onCreate(Bundle savedInstanceState ) {
    super.onCreate(savedInstanceState);
    if(getResources().getConfiguration().orientation==
    Configuration.ORIENTATION_LANDSCAPE) {
        setContentView(R.layout.activity_landscape) ;
    } else {
        setContentView(R.layout.activity_main) ;
    }
    getWindow().setSoftInputMode (
            WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) ;
}
}

How am I suppose to implement all of these methods into my code? Whenever I try I get errors. I'm unsure how to run all of these at once or individually. He wants us to implement and find out what each one does.

Javaturtle
  • 329
  • 1
  • 2
  • 13
  • You would need to post the errors you get if you want help. – codeMagic Oct 04 '16 at 23:20
  • 1
    I'm lost I don't know what I am doing. I'm guessing to find out when a method does something I would need to have some sort of println correct? So I assume you would place onStart{ Println("works')}, but I'm not sure if that is the correct way. – Javaturtle Oct 04 '16 at 23:22
  • 2
    You'll probably want to read [this SO post](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) if it is crashing. If they are compile errors then you need to read them and look up what they mean. If you are still stuck after that, post what the errors are with your question. But yes, look at using `Log` or a `Toast` to quickly see when certain methods are called. – codeMagic Oct 04 '16 at 23:26
  • Please show what code you tried and what errors you get. – Code-Apprentice Oct 04 '16 at 23:35
  • 3
    You should also read about [the Activity Lifecycle](https://developer.android.com/training/basics/activity-lifecycle/index.html). – Code-Apprentice Oct 04 '16 at 23:36

1 Answers1

1

Use a method under create method.

`@Override
protected  onstart()
{
super.onPause();
Log.i(app."on Pause")
}`

Do that for each method and watch the log as its called.

TimmRH
  • 142
  • 1
  • 1
  • 9