• 旺仔闲来无事,练习Intent的带返回信息的打开方式


    package com.hanqi.myintent;
    
    import android.content.Intent;
    import android.net.Uri;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;
    
    import javax.xml.transform.Result;
    
    public class TestIntent extends AppCompatActivity {
        EditText et_1;
        String name,name1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test_intent);
            et_1=(EditText)findViewById(R.id.et_1);
        }
        public void bt_OnClick(View v)
        {
            Intent intent=new Intent(TestIntent.this,TestIntent1.class);
            startActivityForResult(intent,1);
        }
        public void bt1_OnClick(View v)
        {
            name1=et_1.getText().toString();
            if (name1.equals(name))
            {
                Toast.makeText(TestIntent.this, "返回信息成功", Toast.LENGTH_SHORT).show();
            }
        }
        public void bt2_OnClick(View v)
        {
            Intent intent1=new Intent(Intent.ACTION_CALL);
            Uri uri=Uri.parse("tel:"+110);
            intent1.setData(uri);
            try{
            startActivity(intent1);
            }catch (Exception e){}
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode==1)
            {
                if (resultCode==RESULT_OK)
                {
                   name=data.getStringExtra("name");
                }
            }
        }
    }
    package com.hanqi.myintent;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;
    
    public class TestIntent1 extends AppCompatActivity {
    EditText et_1;
        String name;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test_intent1);
            et_1=(EditText)findViewById(R.id.et_1);
        }
        public void bt_OnClick(View v)
        {
            name=et_1.getText().toString();
            Intent intent=new Intent();
            intent.putExtra("name",name);
            setResult(RESULT_OK, intent);
            finish();
        }
        public void bt1_OnClick(View v)
        {
            setResult(RESULT_CANCELED,null);
            finish();
        }
    }
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.hanqi.myintent.TestIntent"
        android:orientation="vertical">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入信息"
            android:id="@+id/et_1"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="带返回的打开方式"
            android:onClick="bt_OnClick"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="返回信息确认"
            android:onClick="bt1_OnClick"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="拨打电话"
            android:onClick="bt2_OnClick"/>
    
    </LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.hanqi.myintent.TestIntent1"
        android:orientation="vertical">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入信息"
            android:id="@+id/et_1"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="返回"
            android:onClick="bt_OnClick"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="取消"
            android:onClick="bt1_OnClick"/>
    
    </LinearLayout>
  • 相关阅读:
    FineReport自学习题第四题——图表
    SQL如何查询连续数字并且统计连续个数
    Arm Cortex-M3 MCU性能
    北汽蓝谷极狐阿尔法S与T
    长鑫存储DDR产品
    华虹宏力芯片制造主流工艺技术
    传统编译器与神经网络编译器
    Apple苹果公司组织架构
    GPU与CPU交互技术
    CMOS图像传感器与DDI显示芯片
  • 原文地址:https://www.cnblogs.com/jiang2538406936/p/5680272.html
Copyright © 2020-2023  润新知