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>