Activity回调方法

1.给activity中的相关回调加log
2.运行到手机,分析各种情况下的log打印情况
第一次运行时:
Activity回调方法_第1张图片
按返回键关闭当前activity:
Activity回调方法_第2张图片
image.png
通过startActivity前往另一个activity
从另一个activity返回该activity
前台显示该activity时按home键
从桌面返回该activity
与activity交互(点击等动作)
在activity上显示一个AlertDialog
Activity回调方法_第3张图片
点击空白或按返回键取消dialog显示
image.png
点击activity上的按钮显示一个Toast
下拉通知栏
  • activity回调方法
public class MainActivity extends AppCompatActivity {

    public static final String TAG = "zhujm";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        log("==>onCreate");
    }

    @Override
    protected void onStart() {
        super.onStart();
        log("==>onStart");
    }

    @Override
    protected void onResume() {
        super.onResume();
        log("==>onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        log("==>onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        log("==>onStop");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        log("==>onRestart");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        log("==>onDestroy");
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        log("==>onWindowFocusChanged   hasFocus:"+hasFocus);

    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        log("==>onAttachedToWindow");

    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        log("==>onDetachedFromWindow");
    }

    @Override
    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        log("==>onUserLeaveHint");
    }

    @Override
    protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
        super.onApplyThemeResource(theme, resid, first);
        log("==>onApplyThemeResource");
    }

    @Override
    public void onPostCreate(@Nullable Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        log("==>onPostCreate");
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        log("==>onPostResume");
    }

    @Override
    public void onAttachFragment(Fragment fragment) {
        super.onAttachFragment(fragment);
        log("==>onAttachFragment");
    }

    @Override
    public void onAttachFragment(android.support.v4.app.Fragment fragment) {
        super.onAttachFragment(fragment);
        log("==>onAttachFragment(v4)");
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        log("==>onTrimMemory  level:"+level);
    }

    @Override
    public void onUserInteraction() {
        super.onUserInteraction();
        log("==>onUserInteraction");
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        log("==>onLowMemory");
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        log("==>onContentChanged");
    }

    @Override
    protected void onResumeFragments() {
        super.onResumeFragments();
        log("==>onResumeFragments");
    }

    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        log("==>onCreateView(String name, Context context, AttributeSet attrs)");
        return super.onCreateView(name, context, attrs);
    }

    @Override
    public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
        log("==>onCreateView(View parent, String name, Context context, AttributeSet attrs)");
        return super.onCreateView(parent, name, context, attrs);
    }

    private void log(String msg) {
        Log.i(TAG,msg);
    }
}

你可能感兴趣的:(Activity回调方法)