显示Intent和隐式Intent
来源:互联网 发布:新网域名转入阿里云 编辑:程序博客网 时间:2024/05/21 22:26
- 显式Intent:通过指定Intent组件名称来实现的,它一般用在知道目标组件名称的前提下,一般是在相同的应用程序内部实现的。
- 隐式Intent:通过IntentFilter来实现的,它一般用在没有明确指出目标组件名称的前提下,一般是用于在不同应用程序之间,必须加上<</span>categoryandroid:name ="android.intent.category.DEFAULT"/>
一.显式Intent
main.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello1"
- />
- <Button
- android:id="@+id/btn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="转到SecondActivity"
- />
- </LinearLayout>
second.xml
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello2"
- />
- <Button
- android:id="@+id/secondBtn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="返回"
- />
- </LinearLayout>
MainActivity.java
- packagecom.android.test.activity;
- importandroid.app.Activity;
- importandroid.content.Intent;
- importandroid.os.Bundle;
- importandroid.view.View;
- importandroid.view.View.OnClickListener;
- importandroid.widget.Button;
- public classMainActivity extends Activity{
- private Buttonbtn;
- @Override
- public voidonCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- btn =(Button)findViewById(R.id.btn);
- //响应按钮btn事件
- btn.setOnClickListener(newOnClickListener() {
- @Override
- public voidonClick(View v) {
- //显示方式声明Intent,直接启动SecondActivity
- Intent it = newIntent(MainActivity.this,SecondActivity.class);
- //启动Activity
- startActivity(it);
- }
- });
- }
- }
SecondActivity.java
- packagecom.android.test.activity;
- importandroid.app.Activity;
- importandroid.content.Intent;
- importandroid.os.Bundle;
- importandroid.view.View;
- importandroid.view.View.OnClickListener;
- importandroid.widget.Button;
- public classSecondActivity extends Activity{
- private ButtonsecondBtn;
- @Override
- protected voidonCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.second);
- secondBtn=(Button)findViewById(R.id.secondBtn);
- //响应按钮secondBtn事件
- secondBtn.setOnClickListener(newOnClickListener() {
- @Override
- public voidonClick(View v) {
- //隐式方式声明Intent,直接启动MainActivity
- Intent intent =newIntent(SecondActivity.this,“com.st.org.main”);
- //启动Activity
- startActivity(intent);
- }
- });
- }
- }
AndroidManifest.xml清单文件,16~18行为SecondActivity在清单文件里的声明
- <?xmlversion="1.0"encoding="utf-8"?>
- <manifestxmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.test.activity"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdkandroid:minSdkVersion="10"/>
- <applicationandroid:icon="@drawable/icon"android:label="@string/app_name">
- <activityandroid:name=".MainActivity"
- android:label="@string/app_name">
- <intent-filter>
- <actionandroid:name="com.st.org.main"/>
- <categoryandroid:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
- <activityandroid:name=".SecondActivity"
- android:label="@string/app_name">
- </activity>
- </application>
- </manifest>
0 0
- 显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 显示intent和隐式intent
- 显示Intent和隐式Intent
- 显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 关于显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 显示Intent和隐式Intent的区别
- Intent对象(三)显示隐式和<intent-filter>
- Android , 浅谈显示Intent和隐式Intent
- 显示Intent和隐式Intent的区别
- 显示Intent和隐式Intent的使用(意图)
- Android—显示Intent和隐式Intent的区别
- 显示Intent和隐示Intent
- Android 显示Intent和隐示Intent
- 显示Intent与隐式Intent
- MySql 编码设置
- Intent的几种有关Activity启动的方…
- 关于手机应用到Samsung Galax…
- 网络协议归纳
- 看过的写的比较好的service之AIDL
- 显示Intent和隐式Intent
- 显示Intent和隐式Intent
- 读取联系人信息
- 优化app速度的几个建议
- 微信企业号开发之-如何获取secret 序列号
- 读取联系人信息
- java并发编程-Executor框架
- notification消息通知与现实多个消…
- 在局域网下网络请求超时不起作用