Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hanqi.text3.MainActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="跳转页面"
android:id="@+id/mybutton"
android:layout_below="@+id/textView"
android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:layout_marginTop="78dp"
android:onClick="onMyButtonClick"
/>
</RelativeLayout>
MainActivity.java
package com.hanqi.text3;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View; //继承了Activity
public class MainActivity extends Activity { @Override //覆盖 重写了父类的onCreate()
protected void onCreate(Bundle savedInstanceState) {
//super 父类
//调用了父类的方法
super.onCreate(savedInstanceState);
//设置Java代码和layout文件的关联
//通过R文件的id值
setContentView(R.layout.activity_main);
}
//按钮点击事件的回调函数
public void onMyButtonClick(View v)
{
Log.e("ATG","按钮点击事件触发");
// Activity2 a2= new Activity2();
//先创建意图 Intent
//第一个参数 来源实例, 就是当前Activity实例
//第二个参数 目标类, 目标Activity的class
Intent in = new Intent(this,Activity2.class); //发动意图
startActivity(in); }
}

需要注意的是这个方法必须符合三个条件:1.public  2.返回void  3.只有一个参数View,这个View就是被点击的这个控件。

 
activity2.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:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="大家好" />
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/et"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="跳转下一个"
android:onClick="onbuttonclick"
/> </LinearLayout>

Activity2.java

package com.hanqi.text3;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText; /**
* Created by Administrator on 2016/3/16.
*/
//回调方法
public class Activity2 extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //
setContentView(R.layout.activity2); System.out.println("这是我运行的第一个Activity"); // Log.d("text", "log输出的信息");
// Log.w("text", "log输出的信息");
// Log.e("text", "log输出的信息");
// Log.i("text","log输出的信息");
// Log.v("text","log输出的信息"); Log.e("TAG","######创建"); }
@Override
protected void onStart(){
super.onStart(); Log.e("ATG","######启动"); }
@Override
protected void onResume(){
super.onResume();
Log.e("ATG", "######显示");
} @Override
protected void onPause(){
super.onPause();
Log.e("ATG", "######暂停");
}
@Override
protected void onStop(){
super.onStop();
Log.e("ATG", "######停止");
}
@Override
protected void onRestart(){
super.onRestart();
Log.e("ATG", "######重新启动");
}
//回调方法
//1.在暂停之后和停止之前保存
int i=0;
String etkey ="edittext";//成员变量
EditText et;
@Override
protected void onSaveInstanceState(Bundle outState) {
//Bundle实际是一个Map,可以存储键值对key/value
i++;
Log.e("ATG","保存="+i); outState.putInt("myKey",i); super.onSaveInstanceState(outState); //保存用户的输入信息
//EditText
//使用id查找并获取View的实例
et= (EditText)findViewById(R.id.et); String str=et.getText().toString();//局部变量 Log.e("TAG","获取用户输入="+str);
outState.getString("edittext",str); } //2.恢复销毁前的保持状态
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState); i = savedInstanceState.getInt("myKey");
Log.e("ATG", "获取="+i); //恢复用户数据
String str = savedInstanceState.getString(etkey);
Log.e("ATG", "获取str="+str);
//设置输入框里面的内容
//操作View的实例
et = (EditText)findViewById(R.id.et);
et.setText(str);
} @Override
protected void onDestroy(){
super.onDestroy();
Log.e("ATG", "######销毁");
} public void onbuttonclick(View v)
{
Intent in = new Intent(this,Activity3.class); startActivity(in);
} }

activity3.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"> <Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="关闭"
android:onClick="onClick"
/>
</LinearLayout>

Activity3.java

package com.hanqi.text3;

import android.app.Activity;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View; /**
* Created by Administrator on 2016/3/19.
*/
public class Activity3 extends Activity { @Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState); setContentView(R.layout.activity3);
}
public void onClick(View v)
{
//关闭
finish();
}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hanqi.text3"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"> <activity android:name=".Activity2" >
<intent-filter>
<action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </activity>
<activity android:name=".Activity3" >
<intent-filter>
<action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </activity> <activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>

Android——Activity跳转的更多相关文章

  1. android activity 跳转传值问题研究

    intent = new Intent(); intent.setClass(LoginActivity.this, RegActivity.class); startActivity(intent) ...

  2. Android Activity跳转动画,让你的APP瞬间绚丽起来

    我们都知道绚丽的APP总会给用户耳目一新的感觉,为了抓住用户更大网络公司使出浑身解数让自己的产品更绚丽,而绚丽最简单的效果就是Activity跳转效果,不仅可以让用户看起来舒服,而且实现起来也特别简单 ...

  3. Android activity跳转方式

    方法一:通过SetContentView切换Layout来实现界面的切换,这种方法相当于重绘Activity. protected void onCreate(Bundle savedInstance ...

  4. [Android]Activity跳转传递任意类型的数据、Activity为SingleTask时代替StartActivityForResult的解决方案

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4389674.html 需求:在ActivityA跳转到Acti ...

  5. Android activity跳转并且回调

    假设A页面要跳到B页面,A页面需要获取B页面传回来的参数来确定显示哪个列表.主要代码如下: 在A页面中:               Intent intent =  new Intent();    ...

  6. Android之Activity跳转

    简述 如果把每个activity看成一个页面的话,那么activity之间的跳转和页面的之间的跳转基本上是一样的.首先需要监听一个事件,当这个事件发生的时候,就进行跳转.html中有个<a sr ...

  7. android intent 隐式意图和显示意图(activity跳转)

    android中的意图有显示意图和隐式意图两种, 显示意图要求必须知道被激活组件的包和class 隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件 A 主activity  B ...

  8. 【原创】Android 从一个Activity跳转到另外一个Activity

    Android四大组件activity使用,实现两个activity之间的跳转 基本流程:创建两个activity-将其中一个activity中组件作为事件源-通过组件事件的处理借助intent对象实 ...

  9. android 15 activity跳转

    从一个屏幕跳到另一个屏幕,一个activity跳转到另一个activity,Intent类用于组件之间传递数据和跳转,组件包括不仅activity. package com.sxt.day04_01; ...

随机推荐

  1. Kubernetes 本地仓库

    1.Kubernetes本地私有仓库 Docker仓库主要用于存放Docker镜像,Docker仓库分为公共仓库和私有仓库,基于registry可以搭建本地私有仓库.使用私有仓库有如下优点: 1)节省 ...

  2. Html----表单元素

    表单元素:用于客户端和服务端进行信息交互的通道 <form></form>:所有的表单元素都应该放在里面 文本输入框: <input type="text&qu ...

  3. 函数式编程语言(Functional Program Language)

    (一) 什么是函数编程语言 简单说,"函数式编程"是一种"编程范式"(programming paradigm),也就是如何编写程序的方法论. 是一种编程典范, ...

  4. ubuntu18换国内源

    编辑/etc/apt/sources.list文件, 在文件最前面添加以下条目(操作前请做好相应备份): ##中科大源 deb https://mirrors.ustc.edu.cn/ubuntu/ ...

  5. 05_ssm基础(三)之Spring基础

    11.spring入门引导 12.spring_HelloWord程序 实现步骤: 0.找到spring压缩包,并解压 1.拷贝jar包 2.添加主配置文件(官方文档约28页) 3.在测试中使用 13 ...

  6. Java 获取一个字符串中,另一个字符串出现的次数

    Java 获取一个字符串中,另一个字符串出现的次数 思想: 1. indexOf到字符串中到第一次出现的索引2. 找到的索引+被找字符串长度,截取字符串3. 计数器++ 代码实现: public cl ...

  7. 游戏编程模式KeyNote

    [游戏编程模式KeyNote] 1.命令模式. 重做在游戏中并不常见,但重放常见.一种简单的重放实现是记录游戏每帧的状态,这样它可以回放,但那会消耗太多的内存.相反,很多游戏记录每个实体每帧运行的命令 ...

  8. python -- 初始函数 函数的定义,函数的返回值以及函数的参数

    1.什么是函数,函数的定义及语法 2.函数的返回值 3.函数的参数 一.函数的定义及语法 函数的定义:定义了一个动作或者功能,是对功能的封装 语法: def 函数名( 形参列表 ):          ...

  9. Vue-axios快速上手(转)

    引入方式: 1 2 3 4 5 $ npm install axios $ cnpm install axios //taobao源 $ bower install axios 或者使用cdn: &l ...

  10. idea使用maven打包jar包

    1.在pom.xml中加入以下内容: <?xml version="1.0" encoding="UTF-8"?> <project xmln ...