- 浏览: 335767 次
- 性别:
- 来自: 安徽
文章分类
最新评论
-
secally:
楼主可以上传个例子吗,谢谢,我咋跑不起来,,eclipse不是 ...
Android自动打包、签名、优化、上传ANT脚本 -
secally:
请问下执行命令是啥,ant release 还是?麻烦指教谢谢 ...
Android自动打包、签名、优化、上传ANT脚本 -
trp1022:
好牛啊
程序员不能不通文史 -
sunny78117:
谢谢,写得好
Android bitmap优化 -
futurebp:
这是什么类型的脚本啊?
Android自动打包、签名、优化、上传ANT脚本
以下内容Sinfrancis版权所有,专注请注明来自 http://mdev.cc/dev
在Android中,传递数据使用Intent,Intent相当于各个Activity之间的桥梁,可以传递数据,可以通过Intent启动另外一个Activity。
Intent有显式和隐式之分,显式的是直接什么要启动的组件,比如Service或者Activity,隐式的通过配置的datatype、url、action来找到匹配的组件启动。
此程序目的:
1、显式启动Activity和service
2、通过隐式的变量,启动Activity和Service
先来看先我们定义的变量类:
package cc.androidos.intent; public class Book { //Intent的数据类型 public static String CONTENT_TYPE = "cc.android/intent.demo"; //Intent中的URL,这里要使用Content开头,不然会找不到组件 public static String CONTENT_URI = "content://test/"; }
程序主界面的代码:还有四个按钮,分别用于启动不同的组件:
package cc.androidos.intent; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Button; public class IntentDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button firstbtn = (Button) findViewById(R.id.firstbtn); Button firstbtnservice = (Button) findViewById(R.id.firstbtnservice); Button secondbtn = (Button) findViewById(R.id.secondbtn); Button secondbtnservice = (Button) findViewById(R.id.secondbtnservice); firstbtn.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { //显式启动FirstIntentDemo Activity Intent i = new Intent(getApplicationContext(),FirstIntentDemo.class); startActivity(i); } }); firstbtnservice.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { //显式启动FirstService 后台服务 Intent i = new Intent(getApplicationContext(),FirstService.class); startService(i); } }); secondbtn.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { //通过Action uri和dataype启动Activity //程序会自动匹配到Intent-Filter配置中有(action属性)Action为Intent.ACTION_VIEW,并且数据类型(data)为cc.android/intent.demo的组件上 Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(Book.CONTENT_URI), Book.CONTENT_TYPE); startActivity(intent); } }); secondbtnservice.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { //通过Action uri和dataype启动Service Intent intent = new Intent(); intent.setAction(Intent.ACTION_EDIT); intent.setDataAndType(Uri.parse(Book.CONTENT_URI), Book.CONTENT_TYPE); startService(intent); } }); } }
以下分别是被启动的组件代码:
显式Activity和Service:
package cc.androidos.intent; import android.app.Activity; import android.os.Bundle; public class FirstIntentDemo extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.firstintent); } } =============================================== package cc.androidos.intent; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public class FirstService extends Service{ @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); String tag = "First Service on Create"; Log.d(tag,"This is the first service..."); } }
隐式启动的Activity和Service:
package cc.androidos.intent; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; public class SecondIntentDemo extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String tag = "SecondIntentDemo onCreate.."; setContentView(R.layout.secondintent); Intent i = getIntent(); Log.d(tag, "intent type : " + i.getType()); Log.d(tag, "intent url : " + i.getData().toString()); } }
===================================
package cc.androidos.intent; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public class SecondService extends Service { @Override public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate(); String tag = "Second service "; Log.d(tag, "Startup second service... "); } }
AndroidManifest.xml文件配置:
这个很重要,需要配置好才行,不然会出现AcitvityNotFoundException
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cc.androidos.intent" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".IntentDemo" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- First Intent Demo --> <activity android:name=".FirstIntentDemo" android:label="@string/app_name"> </activity> <!-- Second Intent Demo --> <activity android:name=".SecondIntentDemo" android:label="@string/app_name"> <intent-filter > <!--The intent filter parameters must match the intent datatype(mimeType) \ action --> <action android:name="android.intent.action.VIEW"/> <data android:mimeType="cc.android/intent.demo"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> <service android:name=".FirstService" > </service> <service android:name=".SecondService" > <intent-filter > <!--The intent filter parameters must match the intent datatype(mimeType) \ action --> <action android:name="android.intent.action.EDIT"/> <data android:mimeType="cc.android/intent.demo"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </service> </application> </manifest>Intent理由个URI属性,这个配合ContentProvider使用,用于数据操纵使用
发表评论
-
抓取Android WebView截屏
2011-08-19 21:33 7604一般使用setDrawingCacheEnabled(true ... -
Android bitmap优化
2011-08-11 17:02 5899直接使用ImageView显示 ... -
Android模拟器更改分辨率后 无法取得分辨率问题
2011-05-11 21:06 2811在PC上更改模拟器分辨率为480*800 (如果你的PC界面 ... -
获取屏幕硬件分辨率方法 收藏
2011-05-11 16:28 1886TextView tv=(TextVie ... -
Bytecode for the Dalvik VM
2011-05-10 22:35 1324http://www.netmite.com/android/ ... -
Android DEX反编译后部分代码解析
2011-05-10 22:07 3877一个private 方法 private Stri ... -
反编译并且修改Android APK包
2011-05-10 16:57 3070為了某個實驗的動機,我們評估反編譯 Android ... -
Android Ant编译时候进行混淆
2010-10-18 13:49 3809版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
自定义Ant Task
2010-09-13 17:58 2968版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
Android自动打包、签名、优化、上传ANT脚本
2010-07-26 16:51 13940版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
Android自定义含有CheckBox的Adapter遇到的问题
2010-06-23 13:48 4092版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
QR code类库
2010-06-03 23:11 2294Google code发现的好东西。 QR code 类库 ... -
Android QQ,一个WEBOS APP诞生!!(两个QQ对比!)
2010-04-10 12:05 1850请看这个大哥的言论 http://linuxtoy.or ... -
Android 、BlackBerry 文本对齐方式对比
2010-02-22 13:11 1782版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
教你如何开关Android的APN网络
2010-01-08 11:36 5974版权所有,转载请注明来自Mobile Developer (h ... -
史上最强NDK入门项目实战
2009-10-10 13:29 2667以下内容Sinfrancis版权所有,专注请注明来自 htt ... -
使用TimerTask控制ProgressBar
2009-10-10 13:21 1051以下内容Sinfrancis版权所有,专注请注明来自 htt ... -
自定义List布局
2009-10-10 13:19 1861以下内容Sinfrancis版权所有,专注请注明来自 htt ... -
重画Progressbar的进度
2009-10-10 13:15 1915以下内容Sinfrancis版权所有,专注请注明来自 htt ... -
谈谈Android中文短信的实现
2009-10-10 13:13 2147似 乎Google在推出G1时 ...
相关推荐
Andriod Intent使用代码举例
Android 通过Intent使用Bundle传递对象 Android开发中有时需要在应用中或进程间传递对象,下面详细介绍Intent使用Bundle传递对象的方法。 被传递的对象需要先实现序列化,而序列化对象有两种方式:java.io....
android Intent使用案例 含:播放多媒体、打电话、发短信、发送email、发邮件、google服务、组件component、action值自定义、显示地图/路径规划、选择应用、打开应用列表、搜索应用等意图实例。
Android-Intent使用方法详解 配合(http://blog.csdn.net/daiyibo123/article/details/51227160)博客查看。使用Android stdio编写。
Android中Intent使用、数据回写(显)
androidIntent使用技巧.pdf
android Intent使用技巧.pdf
最简单intent使用Activity切换实例 按button进入act2
intent使用源码实例.
Intent的示例,详细的注释,详细讲解了startActivityForResult的用法,以及Bundle跟Intent保存对象的机制.
源程序关于android平台中intent的使用小示例,仅供参考
初学移动应用公开发中的Android开发,实验四的主要内容为intent的使用,通过这一次实验,掌握基本的intent使用方法。 具体实验分析 实验第一步:阅读官方文档:intent 实验解析:本次实验共分为两个部分。第一个部分...
开发一年多android 对intent 一般用到的地方总结了一下!
这里总结一些重用的Intent使用,仅供参考。 下面直接给我学习的实例片段。 1,调用web浏览器 Uri myBlogUri = Uri.parse("http://kuikui.javaeye.com"); returnIt = new Intent(Intent.ACTION_VIEW, myBlogUri); 2...
Android开发中有时需要在应用中或进程间传递对象,下面详细介绍Intent使用Bundle传递对象的方法。 被传递的对象需要先实现序列化,而序列化对象有两种方式:java.io.Serializable和android.os.Parcelable Java中...
在Android中通过Intent使用Bundle传递对象源码
使用Intent打开网页
使用Intent拨打电话