package blue.boki.com.emojidemo; import android.app.Activity; import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.Toast; public class LifeActivity extends Activity implements View.OnClickListener{ private Button btn; @Override 创建的时候被调用 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_life); Toast.makeText(this,"onCreate",Toast.LENGTH_LONG).show(); btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(this); } 创建或者后台重新回到前台时期调用 protected void onStart(){ super.onStart(); Toast.makeText(this,"onStart",Toast.LENGTH_LONG).show(); } 从后台重新回到前台时被调用 protected void onRestart() { super.onRestart(); Toast.makeText(this,"onRestart",Toast.LENGTH_LONG).show(); } 创建、覆盖、后台重新回到前台时被调用 protected void onResume() { super.onResume(); Toast.makeText(this,"onResume",Toast.LENGTH_LONG).show(); } 覆盖到下面或者锁屏时被调用 protected void onPause() { super.onPause(); Toast.makeText(this,"onPause",Toast.LENGTH_LONG).show(); } 退出,或者跳转 protected void onStop() { super.onStop(); Toast.makeText(this,"onStop",Toast.LENGTH_LONG).show(); } 退出当前Activity,调用之后的Activity protected void onDestroy() { super.onDestroy(); Toast.makeText(this,"onDestroy",Toast.LENGTH_LONG).show(); } @Override public void onClick(View v) { Intent intent = new Intent(this,ApplyActivity.class); startActivity(intent); } }
Activity的生命周期
最新推荐文章于 2021-12-30 16:28:26 发布