dnf诡秘之森在哪,天天向上林志玲,竺延风被调查
目录
startactivity()
startactivityforresult()
:希望返回结果
启动一个不适用用户界面而在后台执行操作的组件
startservice()
:下载文件等,可携带任何必要的数据bindservice()
: 使用客户端-服务器接口,从其他组件绑定到此服务
广播是任何应用均可接收的消息。系统将针对系统事件(例如:系统启动或设备开始充电时)传递各种广播
sendbroadcast()
sendorderedbroadcast()
sendstickybroadcast()
按名称(完全限定类名)指定要启动的组件
// executed in an activity, so 'this' is the context // the fileurl is a string url, such as "http://www.example.com/image.png" intent downloadintent = new intent(this, downloadservice.class); downloadintent.setdata(uri.parse(fileurl)); startservice(downloadintent);
不会指定特定的组件,而是声明要执行的常规操作,从而允许其他应用中的组件来处理它。
// create the text message with a string intent sendintent = new intent(); sendintent.setaction(intent.action_send); sendintent.putextra(intent.extra_text, textmessage); sendintent.settype("text/plain"); // verify that the intent will resolve to an activity if (sendintent.resolveactivity(getpackagemanager()) != null) { startactivity(sendintent); }
intent包含的主要信息如下:
action_view
action_send
<activity android:name="mainactivity"> <!-- this activity is the main entry, should appear in app launcher --> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="shareactivity"> <!-- this activity handles "send" actions with text data --> <intent-filter> <action android:name="android.intent.action.send"/> <category android:name="android.intent.category.default"/> <data android:mimetype="text/plain"/> </intent-filter> <!-- this activity also handles "send" and "send_multiple" with media data --> <intent-filter> <action android:name="android.intent.action.send"/> <action android:name="android.intent.action.send_multiple"/> <category android:name="android.intent.category.default"/> <data android:mimetype="application/vnd.google.panorama360+jpg"/> <data android:mimetype="image/*"/> <data android:mimetype="video/*"/> </intent-filter> </activity>
第一个 activity mainactivity 是应用的主要入口点。当用户最初使用启动器图标启动应用时,该 activity 将打开:
第二个 activity shareactivity 旨在便于共享文本和媒体内容。 尽管用户可以通过从 mainactivity 导航进入此 activity,但也可以从发出隐式 intent(与两个 intent 过滤器之一匹配)的另一应用中直接进入 shareactivity
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android studio开发小型对话机器人app(实例代码)
Android通过Java sdk的方式接入OpenCv的方法
Android 通过cmake的方式接入opencv的方法步骤
Android Studio finish()方法的使用与解决app点击“返回”(直接退出)
Android 进度条 ProgressBar的实现代码(隐藏、出现、加载进度)
网友评论