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 ...
随机推荐
- JS实现图片懒加载插件
一.前言 我在前几篇博客的记录中,有说自己在做一个图片懒加载的功能,然后巴拉巴拉的遇到哪些问题,结果做完了也没对懒加载这个功能做一些记录,所以这篇文章主要针对我所实现的思路,以及代码做个记录,实现不佳 ...
- Debatching(Splitting) XML Message in Orchestration using DefaultPipeline - BizTalk 2010
Debatching(Splitting) XML Message in Orchestration using DefaultPipeline - BizTalk 2010 In this po ...
- JavaWeb学习 (十三)————JSP
一.什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写h ...
- LeetCode 键盘行-Python3.7<四>
500. 键盘行 题目网址:https://leetcode-cn.com/problems/keyboard-row/hints/ 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词. ...
- mui 实用封装销毁页面
/* * 描述:页面销毁封装 * 说明:针对订单特殊定位页面 * 返回首页,页面空白前进行销毁页面处理 * 使用:plusReady之后 */ (function(w) { var destructi ...
- Java 面向对象编程小练习(曾经)
最近打算将之前学习过的小练习分享出来,算是巩固知识.虽然是小练习,但是越看越觉得有趣,温故而知新. 练习:功能跳水比赛,8个评委评分.运动员成绩去掉最高和最低之后的平均分 代码实例: 1.导包 imp ...
- response slider
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- blfs(systemv版本)学习笔记-配置远程连接显示中文
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 远程连接的lfs系统需要具备以下环境便可在xshell或其他远程终端上面显示中文: 1.lfs主机设置中文编码(需要配置) 2. ...
- web全栈架构师[笔记] — 01 ECMAScript6新特性
ES6新特性 一.变量 var:重复定义不报错:没有块级作用域:不能限制修改 let:变量,不能重复定义,有块级作用域 const:常量,不能重复定义,有块级作用域 二.函数/参数 箭头函数——简写: ...
- Salesforce的翻译工作台
翻译工作台 Salesforce提供了翻译工作台.在这里管理员可以对各种数据进行翻译设置,包括对象信息.字段信息.验证规则.错误信息等. 翻译工作台集中了翻译的内容,从而使得管理员或开发者不需要在其他 ...