Android开发学习笔记:浅谈显示Intent和隐式Intent
来源:互联网 发布:源码修改内核打印级别 编辑:程序博客网 时间:2024/05/28 15:29
原文出处:http://liangruijun.blog.51cto.com/3061169/655132
- 显式Intent:通过指定Intent组件名称来实现的,它一般用在知道目标组件名称的前提下,一般是在相同的应用程序内部实现的。
- 隐式Intent:通过Intent Filter来实现的,它一般用在没有明确指出目标组件名称的前提下,一般是用于在不同应用程序之间。
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns: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>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns: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>
- package com.android.test.activity;
- 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 MainActivity extends Activity {
- private Button btn;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- btn = (Button)findViewById(R.id.btn);
- //响应按钮btn事件
- btn.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- //显示方式声明Intent,直接启动SecondActivity
- Intent it = new Intent(MainActivity.this,SecondActivity.class);
- //启动Activity
- startActivity(it);
- }
- });
- }
- }
- package com.android.test.activity;
- 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 SecondActivity extends Activity {
- private Button secondBtn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.second);
- secondBtn=(Button)findViewById(R.id.secondBtn);
- //响应按钮secondBtn事件
- secondBtn.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- //显示方式声明Intent,直接启动MainActivity
- Intent intent = new Intent(SecondActivity.this,MainActivity.class);
- //启动Activity
- startActivity(intent);
- }
- });
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.test.activity"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="10" />
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".MainActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".SecondActivity"
- android:label="@string/app_name">
- </activity>
- </application>
- </manifest>
- package com.android.change.activity;
- 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 MainActivity extends Activity {
- private Button btn;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- btn = (Button) findViewById(R.id.btn);
- // 响应按钮btn事件
- btn.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // 实例化Intent
- Intent it = new Intent();
- //设置Intent的Action属性
- it.setAction("com.android.activity.MY_ACTION");
- // 启动Activity
- startActivity(it);
- }
- });
- }
- }
- package com.android.change.activity;
- import android.app.Activity;
- import android.os.Bundle;
- public class SecondActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.second);
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns: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"
- />
- <Button
- android:id="@+id/btn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="转到SecondActivity"
- />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns: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/second"
- />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.change.activity"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="10" />
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".MainActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".SecondActivity" >
- <intent-filter>
- <action android:name = "com.android.activity.MY_ACTION" />
- <category android:name = "android.intent.category.DEFAULT" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
0 0
- Android开发学习笔记(4):浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- Android , 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- Android:Intent 显示和隐式 学习
- Android 开发中 Intent 和 Intent 过滤器学习笔记
- Android 显示Intent和隐示Intent
- Android—显示Intent和隐式Intent的区别
- Swift学习笔记(三十三)——常量参数,变量参数和inout参数
- 《程序员面试金典》回文链表
- cent6 安装rdp
- 一般线性规划求最大值
- HDU 4746 Mophues(莫比乌斯反演)
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- 使用maven-shade-plugin构建可执行jar
- 接口和抽象类的区别,这种题目有意思吗?
- UVA - 11165 Galactic Travel(bfs+尺取法+并查集)
- QT 不找到不QAxObject 文件
- UGUI4.6---InputField
- 怎么注释java
- Android性能优化(四),网络优化 && 耗电量优化
- 创建ActiveX简单步骤