android:跳转,Intent,有无返回值

2014-08-17

<!-- 第一个页面 -->

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="126dp"
        android:text="返回的参数值" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/textView1"
        android:text="无返回值跳转" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button1"
        android:layout_below="@+id/button1"
        android:text="有返回值跳转" />
<!-- 第二个页面 -->

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
 1 //java 第一个页面
 2
 3 public class MainActivity extends ActionBarActivity {
 4     private Button bt1;
 5     private Button bt2;
 6     private TextView tv;
 7
 8     @Override
 9     protected void onCreate(Bundle savedInstanceState) {
10         super.onCreate(savedInstanceState);
11         setContentView(R.layout.fragment_main);
12
13         /**
14          * 两种跳转方法
15          * 1、无返回值  使用 startActivity(intent);
16          * 2、有返回结果的跳转 使用 startActivityForResult(intent, requestCode);
17          */
18         bt1 = (Button) findViewById(R.id.button1);
19         bt2 = (Button) findViewById(R.id.button2);
20         tv = (TextView) findViewById(R.id.textView1);
21
22         bt1.setOnClickListener(new OnClickListener() {
23
24             @Override
25             public void onClick(View v) {
26                 // TODO 自动生成的方法存根
27                 Intent intent = new Intent(MainActivity.this, Change.class);
28                 startActivity(intent);            //第一种方法
29             }
30         });
31
32         bt2.setOnClickListener(new OnClickListener() {
33
34             @Override
35             public void onClick(View v) {
36                 // TODO 自动生成的方法存根
37                 Intent intent = new Intent(MainActivity.this, Change.class);
38                 /**
39                  * 第二种方法
40                  * @intent:Intent 对象
41                  * @requestCode: 请求的标识,这里写 1
42                  */
43                 startActivityForResult(intent, 1);
44             }
45         });
46     }
47
48
49     /**
50      * 通过startActivityForResult跳转,接收返回的数据
51      * @requestCode: 请求的标识
52      * @resultCode: 接收返回的标识
53      * @data: 接收的数据
54      */
55     @Override
56     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
57         // TODO 自动生成的方法存根
58         super.onActivityResult(requestCode, resultCode, data);
59         if (requestCode==1 && resultCode==2) {
60             String content = data.getStringExtra("data");
61             tv.setText(content);
62         }
63     }
64 }
 1 //java 第二个页面
 2
 3 public class Change extends Activity{
 4     private Button bt;
 5
 6     @Override
 7     protected void onCreate(Bundle savedInstanceState) {
 8         // TODO 自动生成的方法存根
 9         super.onCreate(savedInstanceState);
10         setContentView(R.layout.change);
11
12         bt = (Button) findViewById(R.id.button1);
13         bt.setOnClickListener(new OnClickListener() {
14
15             @Override
16             public void onClick(View v) {
17                 // TODO 自动生成的方法存根
18                 Intent data  = new Intent();
19                 data.putExtra("data", "你好");
20                 setResult(2,data);        //发送出去的标识
21                 finish();             //关闭页面
22             }
23         });
24
25     }
26
27 }

显示效果:

android:跳转,Intent,有无返回值

时间: 2024-08-04 18:45:46

android:跳转,Intent,有无返回值的相关文章

android基础 sqlite listview activity返回值

android基础  sqlite listview activity返回值 [1].[代码] [Java]代码 跳至 [1] [2] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

函数(定义,有无返回值,参数以及传参问题)

1.定义 def test(): x+=1 return x好处:*减少代码重用 *保持一致性和易维护性 *可扩展性2.关于有无返回值 无:过程就是没有返回值的函数 有:一个————返回本身 def test(): s=[5,4,32,556,22] return s print(test()) #打印结果 [5, 4, 32, 556, 22] 多个————返回元祖 def test(): l=[5,4,32,556,22] s='fjy' return l,s print(test()) #

Android Service 中 onStartCommand()函数返回值含义

onStartCommand()是由Android系统调用的,本质上也是调用了onStart()方法. onStartCommand()返回值有几种: 1)START_STICKY 英文解释: Constant to return from onStartCommand: if this service's process is killed while it is started (after returning from onStartCommand), then leave it in t

stl中的transform()注意其与for_each的不同点(有无返回值)

#include<iostream> using namespace std; #include"vector" #include"algorithm" #include"list" #include"functional" // void PrintV(vector <int > &temp) { for (vector<int>::iterator it = temp.begin

Android跳转intent简单教程

跳转的方法: 1)简单跳转,没有带参的: private void onClickLisener() { // TODO Auto-generated method stub btn_login_register.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //意图.意向,参数1:表示当前在哪里,

html中提交表单并实现不跳转页面处理返回值

<html> <head> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script> <!-- 处理iframe回调的代码块 --> <script type="text/javascript"> var handlerFlag

Activity的跳转及返回值,activity的生命周期

Activity生命周期 从创建到销毁的生命周期: onCreate()→onStart()→onResume()→onPouse()→onStop()→onDestroy() 从起动到后台再到前台: onCreate()→onStart()→onResume()→onPouse()→onStop()→onRestart()→onStart()→onResume() 启动第二个activity 1. 创建new activity 2. 创建对应的new xml布局文件 3. 在new activ

页面跳转(带返回参数的)---------android

在网上看了很多的按钮点击事件,,,都是配置监听什么的.....我用的不是配置监听. 是和winform事件相似的方法,首先要有两个界面,在界面的button中添加onclick事件: 这是第一个主界面中的按钮<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" androi

Activity的跳转及返回值 的四种方法

Activity生命周期 从创建到销毁的生命周期: onCreate()→onStart()→onResume()→onPouse()→onStop()→onDestroy() 从起动到后台再到前台: onCreate()→onStart()→onResume()→onPouse()→onStop()→onRestart()→onStart()→onResume() 启动第二个activity 1.创建new activity 2.创建对应的new xml布局文件 3.在new activity