- package com.tqc.gdd01;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class GDD01 extends Activity
- {
- private static final String TAG = "Android_Log";
- private TextView tv;
- private Button b1;
- private Button b2;
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if(requestCode == 1999)
- {
- tv.setText(resultCode + "");
- }
- }
- @Override
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- tv=(TextView) findViewById(R.id.text1);;
- b1 = (Button) findViewById(R.id.button1);
- b2 = (Button) findViewById(R.id.button2);
- b1.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v){
- Intent intent = new Intent(GDD01.this,GDD01_2.class);
- startActivityForResult(intent,1999);
- }
- });
- b2.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v){
- finish();
- }
- });
- Log.i(TAG, "oncreate()");
- }
- @Override
- public void onStart(){
- super.onStart();
- Log.i(TAG, "onStart()");
- }
- @Override
- public void onResume(){
- super.onResume();
- Log.i(TAG, "onResume()");
- }
- @Override
- public void onPause(){
- super.onPause();
- Log.i(TAG, "onPause()");
- }
- @Override
- public void onStop(){
- super.onStop();
- Log.i(TAG, "onStop()");
- }
- @Override
- public void onRestart(){
- super.onRestart();
- Log.i(TAG, "onRestart()");
- }
- @Override
- public void onDestroy(){
- super.onDestroy();
- Log.i(TAG, "onDestroy()");
- }
- }
複製代碼- package com.tqc.gdd01;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- /**
- * Created by student on 2019/6/15.
- */
- public class GDD01_2 extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.mylayout);
- Button btn =(Button)findViewById(R.id.button2);
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- setResult(99);
- finish();
- }
- });
- }
- }
複製代碼 |