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的主题设置成透明的,这样在 ...
随机推荐
- mongodb 数据库导入.cvs文件时某些字段类型变成NumberLong的解决办法
在mongodb中导入数据时,会在数据库中生成字段记录为NumberLong的数据,可以使用以下方式将其转换为String db.Account.find().forEach( function(it ...
- JavaScript高级程序设计:第十章
一.理解包含不同层次节点的DOM 1.节点层次 以下面的HTML为例: <html> <head> <title>Sample Page</title> ...
- CSS3秘笈:第一章
1.<div>和<span>标签: <div>和<span>标签:就像是一个空的容器,我们要往里面填充内容.一个div就是一个块,意味着它的前后都要空一 ...
- android动态添加TextView或者ImageView
动态添加 text1=new TextView(this); text1.setText("动态添加"); ((LinearLayout) this.findViewById(R. ...
- SpringSecurity自定义过滤器
applicationContext-security.xml: <beans:beans xmlns="http://www.springframework.org/schema/s ...
- MySQL函数大全【转载】
转载自 http://www.jb51.net/article/40179.htm 一.数学函数ABS(x) 返回x的绝对值BIN(x) 返回x的二进制(OCT返回八进制,HEX返回十六进制) ...
- Puppent 介绍原理及安装
Puppet原理: Puppet是一个或者多个master,众多client,所有的客户端都定期(默认为30分钟)使用facter工具把 客户端的基本信息,通过https的xmlrpc协议发送给服务器 ...
- Stm32 Bootloader整理
Stm32 Bootloader整理 一. 基本概念 1.IAP IAP是In Application Programming的首字母缩写,IAP是用户自己的程序在运行过程中对User ...
- hibernate ——helloWorld程序(annotation配置)
在 <hibernate ——helloWorld程序(XML配置)>基础上,修改.添加部分文件: 1.Teacher类和Teacher表 package com.pt.hiberna ...
- SCP测试服务器的上行/下行带宽
SCP测试服务器的上行/下行带宽,这个咋弄呢?有时间再研究一下.