Android-生命周期方法

/**********************************************************************************/

package com.cs.dxm.activity04;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

public class Activity04 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_04);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        System.out.println("First Activity->On Create");
        Button myButton = (Button)findViewById(R.id.myButton);
        myButton.setText("Open Other Activity");
        myButton.setOnClickListener(new MyButtonListener());
    }

    class MyButtonListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.putExtra("testIntent","123");
            intent.setClass(Activity04.this,OtherActivity.class);
            Activity04.this.startActivity(intent);


        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        System.out.println("First Activity->on Start");
    }

    @Override
    protected void onResume() {
        super.onResume();
        System.out.println("First Activity->on Resume");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        System.out.println("First Activity->On Restart");
    }

    @Override
    protected void onPause() {
        super.onPause();
        System.out.println("First Activity->On Pause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        System.out.println("First Activity->on Stop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.out.println("First Activity->on Destroy");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_activity04, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}


 

 

/***************************************************************************************/

package com.cs.dxm.activity04;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

public class OtherActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        System.out.println("Other Activity->on Create");
    }

    @Override
    protected void onStart() {
        super.onStart();
        System.out.println("Other Activity->on Start");
    }

    @Override
    protected void onResume() {
        super.onResume();
        System.out.println("Other Activity->on Resume");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        System.out.println("Other Activity->On Restart");
    }

    @Override
    protected void onPause() {
        super.onPause();
        System.out.println("Other Activity->On Pause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        System.out.println("Other Activity->on Stop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.out.println("Other Activity->on Destroy");
    }


}

 

 

/*****************************************************************************************/

 


I/System.out: First Activity->On Create
I/System.out: First Activity->on Start
I/System.out: First Activity->on Resume


I/System.out: Other Activity->on Create
I/System.out: Other Activity->on Start
I/System.out: Other Activity->on Resume
I/System.out: First Activity->on Stop
I/System.out: Other Activity->On Pause
I/System.out: First Activity->On Restart
I/System.out: First Activity->on Start
I/System.out: First Activity->on Resume
I/System.out: Other Activity->on Stop
I/System.out: Other Activity->on Destroy
I/System.out: First Activity->On Pause
I/System.out: First Activity->on Stop
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值