Activity跳转的几种方式
来源:互联网 发布:ubuntu翻译软件 编辑:程序博客网 时间:2024/06/05 16:21
今天来说说Activity的跳转的三种方式:1. 显示跳转;2. 隐式跳转;3. ComponentName方式跳转。
一、显示跳转
Intent intent2 = new Intent(MainActivity.this,SecondActivity.class); startActivity(intent2);
二、隐式跳转
1. java代码
Intent intent3 = new Intent();intent3.setAction("com.czj.yinshi");tartActivity(intent3);
2. AndroidMainifest.xml配置
<activity android:name=".YinshiActivity"> <intent-filter> <action android:name="com.czj.yinshi"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
三、ConponentName方式跳转
Intent intent1 = new Intent();intent1.setComponent(new ComponentName("com.czj.componentnamedemo", "com.czj.componentnamedemo.SecondActivity"));startActivity(intent1);
1. MainActivity.java
package com.czj.componentnamedemo;import android.content.ComponentName;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button button1,button2,button3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button1 = (Button) findViewById(R.id.btn1); button2 = (Button) findViewById(R.id.btn2); button3 = (Button) findViewById(R.id.btn3); button1.setOnClickListener(this); button2.setOnClickListener(this); button3.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn1: //ComponentName方式跳转 Intent intent1 = new Intent();
//参数一:包名 参数二:SecondActivity 的全包名 intent1.setComponent(new ComponentName("com.czj.componentnamedemo", "com.czj.componentnamedemo.SecondActivity")); startActivity(intent1); break; case R.id.btn2: Intent intent2 = new Intent(MainActivity.this,SecondActivity.class); startActivity(intent2); break; case R.id.btn3: Intent intent3 = new Intent(); intent3.setAction("com.czj.yinshi"); startActivity(intent3); break; default: break; } }}
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.czj.componentnamedemo"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name=".SecondActivity"/> <activity android:name=".YinshiActivity"> <intent-filter> <action android:name="com.czj.yinshi"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </activity> </application></manifest>//隐式跳转要注意下面
<action android:name="com.czj.yinshi"/><category android:name="android.intent.category.DEFAULT"/>
0 0
- android Activity 的几种跳转方式
- Activity的几种跳转方式
- 几种Activity的跳转方式
- Activity跳转的几种方式
- Activity的几种跳转及传值方式详解
- Android之Activity的几种跳转方式
- Android之Activity的几种跳转方式 【转】
- Android之Activity的几种跳转方式
- Android之Activity的几种跳转方式
- Android之Activity的几种跳转方式
- Android之Activity的几种跳转方式
- 安卓Activity跳转的几种方式
- Android之Activity的几种跳转方式
- Android之Activity的几种跳转方式
- 安卓中的Activity的几种跳转方式
- 【转】Android中Activity的几种跳转方式
- 用意图实现activity跳转的几种方式
- 安卓Activity跳转的几种方式
- http协议
- 16年11月03问题汇总
- Shiro在Spring中的缓存配置
- 1.js判断浏览器版本或类型
- nginx配置:反向代理 负载均衡 后端健康检查 缓存
- Activity跳转的几种方式
- onKeyDown事件,设置按返回键间隔不超过两秒时退出程序问题
- hdu 1050
- jQuery构造器
- Leetcode
- CSDN-markdown语法——缩进、图片居中、字体、字号与颜色
- 关于c#调用c++dll问题
- 苏嵌5 16.11.3
- 大数据Hadoop基础