Activity声明周期2
FirstActivity.java
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent; public class FirstActivity extends Activity {
private Button myButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
System.out.println("FirstActivity ---> onCreate ");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
myButton = (Button) findViewById(R.id.myButton);
myButton.setOnClickListener(new ButtonListener());
} @Override
protected void onDestroy() {
System.out.println("FirstAcvity --->onDestory");
super.onDestroy();
} @Override
protected void onPause() {
System.out.println("FirstAcvity --->onPause");
super.onPause();
} @Override
protected void onRestart() {
System.out.println("FirstAcvity --->onRestart");
super.onRestart();
} @Override
protected void onResume() {
System.out.println("FirstAcvity --->onResume");
super.onResume();
} @Override
protected void onStart() {
System.out.println("FirstAcvity --->onStart");
super.onStart();
} @Override
protected void onStop() {
System.out.println("FirstAcvity --->onStop");
super.onStop();
} class ButtonListener implements OnClickListener{ @Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(FirstActivity.this, SecondActivity.class);
FirstActivity.this.startActivity(intent);
} }
}
activity_activity.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_world"
/>
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/first_button"
/>
</LinearLayout>
SecondActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class SecondActivity extends Activity{
private Button secondButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
System.out.println("SecondActivity--->onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second); secondButton = (Button)findViewById(R.id.secondButton);
secondButton.setOnClickListener(new ButtonListener());
} @Override
protected void onDestroy() {
System.out.println("SecondActivity--->onDestory");
super.onDestroy();
} @Override
protected void onPause() {
System.out.println("SecondActivity--->onPause");
super.onPause();
} @Override
protected void onRestart() {
System.out.println("SecondActivity--->onRestart");
super.onRestart();
} @Override
protected void onResume() {
System.out.println("SecondActivity--->onResume");
super.onResume();
} @Override
protected void onStart() {
System.out.println("SecondActivity--->onStart");
super.onStart();
} @Override
protected void onStop() {
System.out.println("SecondActivity--->onStop");
super.onStop();
} class ButtonListener implements OnClickListener{ @Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(SecondActivity.this, FirstActivity.class);
SecondActivity.this.startActivity(intent);
} }
}
activity_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="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/secondButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/second_button"
/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mars.activity05"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="18" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.mars.activity05.FirstActivity"
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="SecondActivity"
android:theme="@android:style/Theme.Dialog"/>
<!--android:theme="@android:style/Theme.Dialog"/>,表示将这个Activity的格式设置为,对话框的形式-->
</application> </manifest>
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Activity05</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="first_button">FirstButton</string>
<string name="second_button">SecondButton</string> </resources>
Activity声明周期2的更多相关文章
- Activity声明周期容易出现的问题
了解activity的生命周期,不仅仅是回答面试官的几个小问题:下面这篇文章不错,截取个人认为优秀的部分分享给大家,欢迎交流.感谢原作者 /** * 示例向我们展示了在 Activity 的配置改变时 ...
- android activity声明周期学习笔记
android生命周期图: Activity继承了ApplicationContext: 1:初次加载activity时顺序执行:onCreate()-->onStart()-->onRe ...
- Activity声明周期1
oncreate():在Activity对象第一次创建时调用 onStart():当Activity变得可见时调用该函数 onResume():当Activity开始准备于用户交互时调用该方法(即获得 ...
- xamarin Android activity生命周期详解
学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...
- Android学习路线(十二)Activity生命周期——启动一个Activity
DEMO下载地址:http://download.csdn.net/detail/sweetvvck/7728735 不像其他的编程模式那样应用是通过main()函数启动的.Android系统通过调用 ...
- activity和fragment的声明周期
Activity生命周期: Fragment生命周期:
- android开发------Activity生命周期
这几天工作比较忙,基本没有什么时间更新播客了. 趁着今晚有点时间,我们来简单说一下什么是Activity生命周期和它们各阶段的特征 什么是生命周期 在还没有接触android开发的时候,听到有人说Ac ...
- Android-管理Activity生命周期 -开始一个Activity
很多程序都是从main()方法开始启动的,和其他程序不同,android是在activity生命周期的特定状态的特定回调方法中初始化代码的.activity启动和销毁的时候都用很多回调方法. 这里将要 ...
- Activity生命周期解决(有图有真相)
Activity完整的生命周期: 启动Activity的周期历程: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcGVuZ2t2/font/5a6L5L2 ...
随机推荐
- mysql 循环
DELIMITER $$ DROP PROCEDURE IF EXISTS student_insert_while; $$ ), in birthday date, in age int) begi ...
- 学习实践之DEMO《nodejs模拟POST登陆》
一个简单的PHP接收参数页面 <?php header("content-type:text/html;charset=utf-8"); if($_POST[username ...
- 一个简单有趣的Python音乐播放器
(赠新手,老鸟绕行0.0) Python版本:3.5.2 源码如下: __Author__ = "Lance#" # -*- coding = utf-8 -*- #导入相应模块 ...
- Infopath 2013 通过UserProfileService读取AD用户信息
我刚刚看过什么C#文章获得当前用户使用Web服务的详细信息. 其实无需编写任何代码,可以实现完全相同的结果.所以我在这里简单的介绍一下: *如果你已经熟悉这个,这个篇文章可以跳过. *此介绍是建立在I ...
- 在C#中,如何连接已加密的Sqlite数据库
对数据加密分两种,一种是对数据库本身进行加密,另一种是对数据表中的数据进行加密, 如果SQLite数据库加密,我这里使用的一个管理工具叫SQLiteDeveloper,如下就可以加密数据库 , 如果在 ...
- 菜鸟入门【ASP.NET Core】5:命令行配置、Json文件配置、Bind读取配置到C#实例、在Core Mvc中使用Options
命令行配置 我们通过vs2017创建一个控制台项目CommandLineSample 可以看到现在项目以来的是dotnet core framework 我们需要吧asp.net core引用进来 ...
- Git实战手册(三): stash解惑与妙用
0. 介绍 教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步原文地址 有空就来看看个人技术小站, 我一直都在 在实际项目开发中,总会遇到代码写到一半(没法去打commit),去开启新 ...
- APP接口调用流程
- HTML5的DeviceOrientation实现微信摇一摇功能
在HTML5中,DeviceOrientation特性所提供的DeviceMotion事件封装了设备的运动传感器时间,通过改时间可以获取设备的运动状态.加速度等数据(另还有deviceOrientat ...
- Maven 环境搭建及使用(win10)
最近由于公司项目需要,学习了一下Maven 环境的配置.这里把配置步骤和简单的操作做一个汇总. 一.Maven环境的搭建 1.配置java环境(这里不详述过程,可参考:http://www.cnblo ...