笔记-Intent跳转
来源:互联网 发布:2016京东618销售数据 编辑:程序博客网 时间:2024/05/16 09:47
一、显式跳转
MainActity.java
import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //设置Button监听 findViewById(R.id.btyStarNewActivity).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent(MainActivity.this, aativity.class));//跳转到 aactivity } }); }}
activity_main.xml 布局
选择线性布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/btyStarNewActivity" android:text="启动一个Activity" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
接下来手动创建一个activity 命名为aactivity.xml
aactivity.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="这是另一个Activity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40dp"/></LinearLayout>
由于这里是手动添加的activity,所以需要在 AndroidMainifest.xml中手动添加入<activity android:name=".aativity"/>
AndroidMainifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="news.com.study_intent"> <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" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".aativity"/> </application></manifest>
aactivity.java
import android.app.Activity;import android.os.Bundle;public class aativity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.aativity); }}
二、隐式跳转
1、直接传入字符串
在AndroidMainifest.xml中设置
<intent-filter> <category android:name="android.intent.category.DEFAULT"/> <!--指明是默认的category,一般在隐式地启动activity时需要用到category [http://blog.csdn.net/ygc87/article/details/7480695]--> <action android:name="asafdd" /> <!--这里的字符串用来传值--> </intent-filter>
AndroidMainifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="news.com.study_intent"> <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" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".aativity"> <intent-filter> <category android:name="android.intent.category.DEFAULT"/> <action android:name="asafdd" /> </intent-filter> </activity> </application></manifest>
MainActivity.java
package news.com.study_intent;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //设置Button监听 findViewById(R.id.btyStarNewActivity).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent("asafdd"));//跳转到 aactivity } }); }}
使用这种方法可以实现 启动另一个APP中的Activity
http://blog.csdn.net/lincyang/article/details/45503675
0 0
- 笔记-Intent跳转
- Android笔记---Intent实现Activity跳转
- Intent的普通跳转和带数据跳转(笔记)
- Intent跳转
- Intent跳转
- Intent跳转
- intent跳转
- intent跳转
- Intent 跳转
- Intent跳转
- Intent跳转
- 跳转,Intent跳转页面
- Android自学笔记之Intent 页面跳转详解
- Android编程学习笔记 之 使用Intent实现页面跳转
- Android - Intent - 界面跳转
- Android - Intent - 界面跳转
- Intent 介绍--窗体跳转
- Intent 各种跳转
- uva 1585 Score
- Mysql常用语句和案例介绍
- CentOS 7.0 关闭防火墙和selinux
- 简单配置搞定 Nginx + Tomcat + HTTPS
- synchronized的使用总结
- 笔记-Intent跳转
- HDU2044 一只小蜜蜂
- Activity间传递参数的四种常用方法
- 每天一道题 NYOJ 906 杨辉三角 (难度1)
- x86上的那些UNIX——BSD篇+主流桌面
- LeetCode119—Pascal's Triangle II
- androidStudio异常:Couldn't load memtrack module (No such file or directory)
- JNI调用Java方法的流程
- SQL Server Data Tools 2013中保存包save copy of