- 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";
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if(requestCode == 1999)
- tv.setText(resultCode+" ");
- }
- private TextView tv;
- private Button b1;
- private Button b2;
- @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 it = new Intent(GDD01.this, GDD01_2.class);
- startActivityForResult(it, 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/22.
- */
- public class GDD01_2 extends Activity{
- @Override
- public 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();
- }
- });
- }
- }
複製代碼- <?xml version="1.0" encoding="utf-8"?>
- <manifest
- package="com.tqc.gdd01"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme">
- <activity
- android:name="com.tqc.gdd01.GDD01"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
- <activity android:name=".GDD01_2"></activity>
- </application>
- </manifest>
複製代碼 |