Android , 浅谈显示Intent和隐式Intent
来源:互联网 发布:filco minila air mac 编辑:程序博客网 时间:2024/05/20 18:44
- 显式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 , 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 浅谈显示Intent和隐式Intent
- 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
- Android—显示Intent和隐式Intent的区别
- 显示Intent和隐式Intent
- 显示intent和隐式intent
- 畅通工程续
- 启动风暴解决方法汇总
- POJ 3630
- 抽象、接口、内部类
- 【Linux网络编程】浅谈 C/S 和 B/S 架构
- Android , 浅谈显示Intent和隐式Intent
- 9.14学习笔记 studiojar包生成,android插件,毛玻璃
- mac下无法识别手机usb问题
- Android开发环境搭建
- 华为荣耀6不显示日志解决方案
- 背包的标准代码与注释
- 一维搜索之黄金分割法(C#实现)
- 黑马程序员——配置,操作文件
- 【iOS】APP实现检测更新