标签:android c class blog code java
搞了这么长时间的android开发,却对一些基础的东西一直模棱两可。。。就比如这个onPause和onStop。如果从一个界面,跳到另一个界面,那么是调用哪个呢?
经过我的实验。搞清楚了。onPause是有活动状态变为非活动状态。onStop()是变为不可见。那么从一个页面跳到另一个页面就是依次调用onPause,onStop.看下程序:
package com.example.fuhe; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View view){ Intent intent = new Intent(); intent.setClass(this, SS.class); startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override protected void onRestart() { super.onRestart(); Log.e("MainActivity", "onRestart"); } @Override protected void onResume() { super.onResume(); Log.e("MainActivity", "onResume"); } @Override protected void onPause() { super.onPause(); Log.e("MainActivity", "onPause"); } @Override protected void onStop() { super.onStop(); Log.e("MainActivity", "onStop"); } }
package com.example.fuhe; import android.app.Activity; import android.os.Bundle; import android.view.View; public class SS extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ss); } public void click(View view){ finish(); } }
标签:android c class blog code java
原文地址:http://blog.csdn.net/tangliuqing/article/details/27397477