- 浏览: 54791 次
- 性别:
- 来自: 北京
博客专栏
-
设计模式
浏览量:7170
文章分类
最新评论
-
alixjiang:
getInstance应该在同步锁的保护之下吧
设计模式-单例模式 -
再_见孙悟空:
就是信息的转发
设计模式-中介者模式 -
DanielHan:
中介者模式中,中介者参与同事角色之间的通信方式,使用的是观察者 ...
设计模式-中介者模式 -
net_hare:
这个和观察者模式有什么区别
设计模式-中介者模式 -
xinglan500:
用代码解释很好哦。多谢博主啦。
JAVA反射机制之一
用法一:跳转后的activity不需要回传参数
send.xml
receive.xml
Send.java
Receive.java
用法二:跳转后的activity需要回传参数
send.xml
receive.xml
Send.java
Receive1.java
Receive2.java
用法二的结果:
send.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转到另一个Activity"/> </LinearLayout>
receive.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/txt" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </LinearLayout>
Send.java
package com.example.intentdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class Send extends Activity { private Button btn=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.send); btn=(Button)findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(Send.this, Receive.class); intent.putExtra("param", "你好!"); startActivity(intent); } }); } }
Receive.java
package com.example.intentdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class Receive extends Activity { private TextView txt=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.receive); txt=(TextView)findViewById(R.id.txt); Intent intent=getIntent(); txt.setText(intent.getStringExtra("param")); } }
用法二:跳转后的activity需要回传参数
send.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/txt" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转到Receive1"/> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转到Receive2"/> </LinearLayout>
receive.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/txt" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="回到第一个Activity"/> </LinearLayout>
Send.java
package com.example.intentdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class Send extends Activity { private Button btn1=null; private Button btn2=null; private TextView txt=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.send); btn1=(Button)findViewById(R.id.btn1); btn2=(Button)findViewById(R.id.btn2); txt=(TextView)findViewById(R.id.txt); btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(Send.this, Receive1.class); intent.putExtra("param", "这是Receive1"); startActivityForResult(intent, 1); } }); btn2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(Send.this, Receive2.class); intent.putExtra("param", "这是Receive2"); startActivityForResult(intent, 2); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK){ switch(requestCode){ case 1: txt.setText("从Receive1返回数据"+data.getStringExtra("ret")); break; case 2: txt.setText("从Receive2返回数据"+data.getStringExtra("ret")); break; default: break; } } } }
Receive1.java
package com.example.intentdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class Receive1 extends Activity { private TextView txt=null; private Button btn=null; private Intent intent=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.receive); txt=(TextView)findViewById(R.id.txt); btn=(Button)findViewById(R.id.btn); intent=getIntent(); txt.setText(intent.getStringExtra("param")); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent.putExtra("ret", "1"); setResult(RESULT_OK, intent); finish(); } }); } }
Receive2.java
package com.example.intentdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class Receive2 extends Activity { private TextView txt=null; private Button btn=null; private Intent intent=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.receive); txt=(TextView)findViewById(R.id.txt); btn=(Button)findViewById(R.id.btn); intent=getIntent(); txt.setText(intent.getStringExtra("param")); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent.putExtra("ret", "2"); setResult(RESULT_OK, intent); finish(); } }); } }
用法二的结果:
发表评论
-
Android中path的arcTo方法的使用
2014-09-26 16:28 1172该方法的声明为: void Android.graphics ... -
drawable不同目录你会怎么选择(Android)
2014-09-26 15:18 640可以接触Android的会有一个疑问,为什么res下面会有这么 ... -
android调用手机联系人
2014-09-24 14:11 0一.选择联系人 startActivityForResul ... -
Android中全屏无标题设置
2014-09-24 13:06 555方法一:在java代码中实现 this.requestWi ... -
tools:context的作用
2014-08-05 13:32 587tools:context="activity na ... -
Android平台调用WebService详解
2014-08-05 10:32 508http://blog.csdn.net/lyq8479/ar ... -
Android开发之WebService介绍
2014-08-05 10:31 556http://blog.csdn.net/lyq8479/ar ... -
Handler
2014-07-16 16:43 520Android中有着和J2SE ... -
java中的匿名内部类总结
2014-07-16 14:45 415匿名内部类也就是没有名字的内部类 正因为没有名字,所以匿名内部 ... -
两分钟彻底让你明白Android Activity生命周期(图文)!
2014-07-16 09:39 569大家好,今天给大家详解一下Android中Activity的生 ... -
StateListDrawable资源
2014-07-15 21:18 1283StateListDrawable用于组织多个Draw ... -
Android home键和back键区别
2014-07-15 13:04 792back键 Android的程序无需刻意的去退出,当你一按下手 ... -
ImageView的ScaleType属性
2014-07-15 12:54 979图片说明Andorid中ImageView的不同属性Scale ... -
存储方式三:数据库SQLite(SQLiteOpenHelper)
2014-07-09 18:23 564SQLHelper.java package com.ex ... -
存储方式二:文件(XML XmlPull解析)
2014-07-09 13:30 5211.读 LinkMan.java package com. ... -
存储方式二:文件(XML SAX解析)
2014-07-08 19:40 381LinkMan.java package com.exam ... -
存储方式二:文件(XML DOM解析)
2014-07-08 19:41 4181.写 package com.example.filed ... -
存储方式二:文件(raw下的文本文件)
2014-07-08 13:47 690package com.example.filedemo; ... -
存储方式二:文件(文本文件)
2014-07-08 13:37 532一.写 FileOutputStream output ... -
存储方式一:SharedPreferences
2014-07-08 10:08 375一.添加数据 SharedPreferences shar ...
相关推荐
Android-Intent使用方法详解 配合(http://blog.csdn.net/daiyibo123/article/details/51227160)博客查看。使用Android stdio编写。
Android Intent 用法汇总
主要介绍Intent的常见用法,收发信息,打电话,浏览图片,发送邮件等等
可以调用打电话、发短信、应用程序等
主要介绍了Android开发中Intent用法,总结分析了Android中Intent的功能、使用方法与相关注意事项,需要的朋友可以参考下
这是一个关于android intent的用法,希望对大家有用,很全的。
本文实例讲述了Android组件之间交互核心Intent用法。分享给大家供大家参考,具体如下: 从一个Activity启动到另一个Activity可以使用startActivity()方法或者是startActivityForResult()方法 第一种:直接启动一个...
举例说明了intent用于broadcast以及service的一些方法
总结android中Intent的用法,约21种。
主要介绍了Android Intent 用法全面总结的相关资料,并附实例代码,需要的朋友可以参考下
主要介绍了Android提高之Activity+Intent用法,是很实用的功能,需要的朋友可以参考下
Android IntAndroid Intent的几种用法全面总结ent的几种用法全面Android Intent的几种用法全面总结总结
将intent对象传给 Context.sendBroadcast(), Context.sendOrderedBroadcast(),或者Context.sendStickyBroadcast()等广播方法,则它们被传给 broadcast receiver. 在上述三种情况下, android系统会自己找到合适的...
初学移动应用公开发中的Android开发,实验四的主要内容为intent的使用,通过这一次实验,掌握基本的intent使用方法。 具体实验分析 实验第一步:阅读官方文档:intent 实验解析:本次实验共分为两个部分。第一个部分...
这个例子主要讲下Intent Filter的用法。对应博客地址:http://blog.csdn.net/chenliqiang12345678/article/details/50568468