当前位置 : 主页 > 编程语言 > c++ >

Activity的简单学习

来源:互联网 收集:自由互联 发布时间:2021-06-30
MainActivity.java package com.test.activitytest;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.view.View;import android.widget.Button;public clas
MainActivity.java
package com.test.activitytest;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    final String tag="tag";
    private Button tb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);
        tb = (Button) findViewById(R.id.button);
        tb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,secActivity.class);
                MainActivity.this.startActivity(intent);
            }
        });
        Log.i(tag,"Activity is onCreate");
    }
    protected void onStart(){
        super.onStart();
        Log.i(tag,"Activity is onStart");
    }
    protected  void onResume(){
        super.onResume();
        Log.i(tag,"Activity is onResume");
    }
    protected  void onPause(){
        super.onPause();
        Log.i(tag,"Activity is onPause");
    }
    protected void onStop(){
        super.onStop();
        Log.i(tag,"Activity is onStop");
    }
    protected  void onDestory(){
        super.onDestroy();
        Log.i(tag,"Activity is onDestory");
    }
    protected void onRestart(){
        super.onRestart();
        Log.i(tag,"Activity is onRestart");
    }
}
secActivity.java
package com.test.activitytest;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;

/**
 * Created by Administrator on 2017/8/28.
 */

public class secActivity extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.seclayout);
    }
}
layout.xml
 

 

    
  

 
seclayout.xml
 

 

    
  

 
AndroidManifest.xml
网友评论