Android--->activity界面跳转,以及查看生命周期过程
main.xml界面布局
<?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/hello"
/>
<Button
android:id="@+id/secondBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second"
/>
<Button
android:id="@+id/thirdBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Third"
/>
</LinearLayout>
second.xml界面布局
<?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="SecondActivity"
/>
</LinearLayout>
third.xml界面布局
<?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="ThirdActivity"
/>
</LinearLayout>
第一个界面操作MainActivity.java
package com.szy.activity; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class MainActivity extends Activity
{
private final static String TAG="MainActivity";
private Button secondBtn=null;
private Button thirdBtn=null; @Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
secondBtn=(Button)findViewById(R.id.secondBtn);
thirdBtn=(Button)findViewById(R.id.thirdBtn);
secondBtn.setOnClickListener(listener);
thirdBtn.setOnClickListener(listener);
Log.i(TAG, "MainActivity-->onCreate");
} @Override
protected void onDestroy()
{
super.onDestroy();
Log.i(TAG, "MainActivity-->onDestroy");
} @Override
protected void onPause()
{
super.onPause();
Log.i(TAG, "MainActivity-->onPause");
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} @Override
protected void onRestart()
{
super.onRestart();
Log.i(TAG, "MainActivity-->onRestart");
} @Override
protected void onResume()
{
super.onResume();
Log.i(TAG, "MainActivity-->onResume");
} @Override
protected void onStart()
{
super.onStart();
Log.i(TAG, "MainActivity-->onStart");
} @Override
protected void onStop()
{
super.onStop();
Log.i(TAG, "MainActivity-->onStop");
} private OnClickListener listener=new OnClickListener()
{ public void onClick(View v)
{
Button btn=(Button)v;
Intent intent=new Intent();
switch (btn.getId())
{
case R.id.secondBtn:
intent.setClass(MainActivity.this, SecondActivity.class);
break;
case R.id.thirdBtn:
intent.setClass(MainActivity.this, ThirdActivity.class);
break;
}
startActivity(intent);
} }; }
第二个界面操作SecondActivity.java
package com.szy.activity; import android.app.Activity;
import android.os.Bundle;
import android.util.Log; public class SecondActivity extends Activity {
private static final String TAG = "MainActivity"; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Log.i(TAG, "SecondActivity-->onCreate");
} @Override
protected void onDestroy()
{
super.onDestroy();
Log.i(TAG, "SecondActivity-->onDestroy");
} @Override
protected void onPause()
{
super.onPause();
Log.i(TAG, "SecondActivity-->onPause");
} @Override
protected void onRestart()
{
super.onRestart();
Log.i(TAG, "SecondActivity-->onRestart");
} @Override
protected void onResume()
{
super.onResume();
Log.i(TAG, "SecondActivity-->onResume");
} @Override
protected void onStart()
{
super.onStart();
Log.i(TAG, "SecondActivity-->onStart");
} @Override
protected void onStop()
{
super.onStop();
Log.i(TAG, "SecondActivity-->onStop");
}
}
第三个界面操作ThirdActivity.java
package com.szy.activity; import android.app.Activity;
import android.os.Bundle;
import android.util.Log; public class ThirdActivity extends Activity
{
private static final String TAG = "MainActivity"; @Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.third);
Log.i(TAG, "ThirdActivity-->onCreate");
} @Override
protected void onDestroy()
{
super.onDestroy();
Log.i(TAG, "ThirdActivity-->onDestroy");
} @Override
protected void onPause()
{
super.onPause();
Log.i(TAG, "ThirdActivity-->onPause");
} @Override
protected void onRestart()
{
super.onRestart();
Log.i(TAG, "ThirdActivity-->onRestart");
} @Override
protected void onResume()
{
super.onResume();
Log.i(TAG, "ThirdActivity-->onResume");
} @Override
protected void onStart()
{
super.onStart();
Log.i(TAG, "ThirdActivity-->onStart");
} @Override
protected void onStop()
{
super.onStop();
Log.i(TAG, "ThirdActivity-->onStop");
}
}
对三个界面activity注册一下
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.szy.activity"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" /> <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>
<activity android:name=".ThirdActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog">
</activity>
</application>
</manifest>
Android--->activity界面跳转,以及查看生命周期过程的更多相关文章
- Android activity界面跳转动画
实现activity界面跳转动画 1.在startActivity方法之后加入: overridePendingTransition(R.anim.pull_in_right, R.anim.pull ...
- Android 中Activity生命周期分析:Android中横竖屏切换时的生命周期过程
最近在面试Android,今天出了一个这样的题目,即如题: 我当时以为生命周期是这样的: onCreate --> onStart -- ---> onResume ---> onP ...
- Android Activity、Service、BroadcastReceiver 的生命周期
Activity.Service.BroadcastReceiver这三个组建是Android开发中最常使用到的组件,在它们的生命周期的各个阶段我们需要针对性的做些事情,了解这些组件的生命周期有利于我 ...
- 17.(转) Android之四大基本组件介绍与生命周期
Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器. 一:了解四大基本组件 Activity ...
- android拾遗——四大基本组件介绍与生命周期
Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器. 一:了解四大基本组件 Activity ...
- Android中startService的使用及Service生命周期
Android中有两种主要方式使用Service,通过调用Context的startService方法或调用Context的bindService方法.本文仅仅探讨纯startService的使用.不 ...
- react组件生命周期过程
实例化 首次实例化 getDefaultProps getInitialState componentWillMount render componentDidMount 实例化完成后的更新 getI ...
- Android之Activity界面跳转--生命周期方法调用顺序
这本是一个很基础的问题,很惭愧,很久没研究这一块了,已经忘得差不多了.前段时间面试,有面试官问过这个问题.虽然觉得没必要记,要用的时候写个Demo,打个Log就清楚了.但是今天顺手写了个Demo,也就 ...
- Android Activity切换(跳转)时出现黑屏的解决方法
在两个Activity跳转时,由于第二个Activity在启动时加载了较多数据,就会在启动之前出现一个短暂的黑屏时间,解决这个问题比较简单的处理方法是将第二个Activity的主题设置成透明的,这样在 ...
随机推荐
- MFC通过ODBC连接Mysql程序
分享到 一键分享 QQ空间 新浪微博 百度云收藏 人人网 腾讯微博 百度相册 开心网 腾讯朋友 百度贴吧 豆瓣网 搜狐微博 百度新首页 QQ好友 和讯微博 更多... 百度分享 MFC通过ODBC连接 ...
- 第三十五节,json数据类型转换字符串模块
在使用json模块时需要先 import json 引入模块 json.dumps()模块函数 功能:将Python数据类型转换成字符串[有参] 使用方法:json.dumps(要转换的数据类型变量) ...
- InjectAPC全部项目(Win32和Win64位)
// InjectAPC.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h> #inclu ...
- flash cs6 更新到Flash player15.0 及Air 更新方法
1.自行下载Air 15.0 sdk (Flash player 包含在内) 2. 到15.0Air 包 里找player :AIR15.0\frameworks\libs\player 里面有pl ...
- DataSet与DataReader的比较
DataSet与DataReader的比较 DataSet DataReader 读或写数据 只读 包含多个来自不同数据库的表 使用 SQL 语句从单个数据库 非连接模式 连接模式 绑定到多个控件 只 ...
- mysql innobackupex备份工具
先简单介绍一下这个工具:innobackupexinnobackupex比xtarbackup有更强的功能,它整合了xtrabackup和其他的一些功能,他不但可以全量备份/恢复,还可以基于时间的增量 ...
- zf-关于更换页面,的各种问题。
问题1:找不到common 这个变量(集合)与layer这个js文件. 这里的common 就是一个方法集合,声明var common; common.abc = function(参数1,参数2, ...
- OpenGL红宝书例3.1 -- glBufferSubData使用
代码实现 1.1 C++部分 GLFWwindow *window; GLuint shader_program; GLuint VAO; void init() { static const GLf ...
- JNI调用问题(部分机型崩溃)
1.今日测试发现在部分手机上游戏会崩溃,通过logcat日志发现是jni调用问题(我猜测) 错误日志中有如下语句: trying to work around app JNI bugs, but di ...
- C++中的函数指针和函数对象总结
篇一.函数指针函数指针:是指向函数的指针变量,在C编译时,每一个函数都有一个入口地址,那么这个指向这个函数的函数指针便指向这个地址.函数指针的用途是很大的,主要有两个作用:用作调用函数和做函数的参数. ...