LifecycleActivity

package com.example.hello;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;

/**
 * 进入手机鼠标第一次点击
 * onCreate
 * onStart
 * onResume
 * 
 * 接着关闭
 * onPause
 * 
 * onStop
 * onDestroy
 * 
 * 
 * 
 * 
 * 
 * @author ZengWenFeng
 *
 */

public class LifecycleActivity extends Activity 
{
	private String tag = LifecycleActivity.class.getSimpleName();

	/**
	 * 1、Activity创建执行
	 */
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lifecycle);
		
		Log.d(tag, "onCreate");
	}
	
	/**
	 * 2、Activity可见时执行
	 */
	protected void onStart()
	{
		super.onStart();
		
		Log.d(tag, "onStart");
	}
	
	/**
	 * 3、Activity可交互时执行
	 */
	protected void onResume()
	{
		super.onResume();
		
		Log.d(tag, "onResume");
	}
	
	/**
	 * 4、Activity重新可见时执行,不是第一次可见
	 */
	protected void onRestart()
	{
		super.onRestart();
		
		Log.d(tag, "onRestart");
	}
	
	/**
	 * 5、Activity暂停执行
	 */
	protected void onPause()
	{
		super.onPause();
		
		Log.d(tag, "onPause");
	}
	
	/**
	 * 6、Activity暂停执行
	 */
	protected void onStop()
	{
		super.onStop();
		
		Log.d(tag, "onStop");
	}
	
	/**
	 * 7、Activity销毁
	 */
	protected void onDestroy()
	{
		super.onDestroy();
		
		Log.d(tag, "onDestroy");
	}
	
	/**
	 * 打开模式为singleTop时候,如果该activity02在栈顶会调用
	 * 
	 * @author zengwenfeng
	 * @date 2015.04.22
	 */
	protected void onNewIntent(Intent intent)
	{
		super.onNewIntent(intent);
		
		Toast.makeText(this, "onNewIntent_message", Toast.LENGTH_SHORT).show();
	}
	
	
	private String value = "value";
	/**
	 * 保存实例状态
	 * 
	 * 1、控件必须要有ID
	 * 2、保存不了变量的值,???
	 */
	protected void onSaveInstanceState(Bundle outState)
	{
		//----------------------------------------------------
		outState.putString("key", value);//保存临时变量
		//----------------------------------------------------
		
		super.onSaveInstanceState(outState);
	}
	
	/**
	 * 还原实例状态
	 * 
	 * (non-Javadoc)
	 * @see android.app.Activity#onRestoreInstanceState(android.os.Bundle)
	 * 
	 * protected void onCreate(Bundle savedInstanceState)
	 */
	protected void onRestoreInstanceState(Bundle savedInstanceState) 
	{
		super.onRestoreInstanceState(savedInstanceState);
		
		
		//----------------------------------------------------
		if (savedInstanceState == null)
		{
			return;
		}
		
		String value = savedInstanceState.getString("key");
		Toast.makeText(this, value, Toast.LENGTH_SHORT).show();
		//----------------------------------------------------
	}
	
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.lifecycle, menu);
		return true;
	}

}

你可能感兴趣的:(js-flex)