现在是可见并且可以被操作,所以现在是一个前台的Activity。

按一下Home键,它是先onPause然后onStop.

现在它就处于一个Stop停止的状态。停止的状态如果我当前内存够用的情况下,它会依然保留当前的所有信息。

如果按多一次Home键还可以把这个东西重新给调出来。

应该不是实体键设置的问题,是操作的问题。按住电脑的home键再点击安卓虚拟设备/模拟器AVD里面的实体键按钮home就可以把当前正在运行的进程调出来。记住电脑的小键盘num lock要打开才可以使用小键盘的home键。

只不过这个时候它是不可见不可被操作。但是所有的状态还会被保存。

重新再把进程调出来运行,这个时候它又处于可见并且可以被操作的状态。这些就是这些生命周期方法。


什么时候它会处于onPause?

为了能让它正确打开必须在清单文件里面声明第二个Activity。怎么能让它处于一个暂停的状态,创建一个透明的应用。

Theme.Translucent.NoTitleBar.Fullscreen

透明主题没有标题栏并且是全屏的。

先运行Day10_06_activity生命周期再运行Day10_07_透明应用,Day10_06_activity生命周期这个应用可见但是不可操作,它处于暂停状态onPause了.


如果开启了应用Day10_06_activity生命周期,然后按一下返回键就onPause->onStop->onDestroy.


如果是处于前台状态,那么就说明onResume被执行完了。前台状态->暂停状态,要执行onPause().暂停状态->前台状态,要执行onResume().

前台状态->停止状态,要执行onPause()和onStop().

销毁状态,就是onPasue()->onStop()->onDestroy().

从停止状态->前台状态,执行onrestart()->onstart()->onresume().但是没有执行onCreate(),说明Activity还是以前的,并没有创建出一个新的Activity.

Activity生命周期的七个方法必须得牢记在心。


package com.itheima.activitylifecycle;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {//onCreate()每一天都在跟它打交道
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("onCreate");
}
public void open(View v){
startActivity(new Intent(this, SecondActivity.class));//显式意图
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
System.out.println("onStart");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
System.out.println("onResume");
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
System.out.println("onPause");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
System.out.println("onStop");
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
System.out.println("onDestroy");
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
System.out.println("onRestart");
}
}
package com.itheima.activitylifecycle;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu; public class SecondActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {//onCreate()每一天都在跟它打交道
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
System.out.println("onCreate");
} @Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
System.out.println("onStart");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
System.out.println("onResume");
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
System.out.println("onPause");
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
System.out.println("onStop");
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
System.out.println("onDestroy");
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
System.out.println("onRestart");
}
}
<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=".MainActivity" > <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="open"
android:text="打开另一个activity" /> </RelativeLayout>
<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=".MainActivity" > <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="open"
android:textColor="#ff0000"
android:text="打开另一个activity" /> </RelativeLayout>
package com.itheima.translucent;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itheima.translucent"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
<activity
android:name="com.itheima.translucent.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>
</application> </manifest>
<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=".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </RelativeLayout>

15_activity生命周期方法说明的更多相关文章

  1. Spring中Bean的生命周期方法

    Bean的生命周期方法 src\dayday\Car.java package dayday;import com.sun.org.apache.xpath.internal.SourceTree;i ...

  2. Activity的生命周期及各生命周期方法的作用

    一.Activity的生命周期中各个方法的作用 onCreate(): 做Activity上所需要数据的初始化工作. onStart(): 显示Activity界面,此时用户对界面可见但不可交互. o ...

  3. Info.plist和pch文件的作用,UIApplication,iOS程序的启动过程,AppDelegate 方法解释,UIWindow,生命周期方法

    Info.plist常见的设置 建立一个工程后,会在Supporting files文件夹下看到一个“工程名-Info.plist”的文件,该文件对工程做一些运行期的配置,非常重要,不能删除 注:在旧 ...

  4. Android 切横竖屏时走的生命周期方法?222

    第一种情况: 不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次 第二种情况: 设置Activity的androi ...

  5. 微信小程序开发之详解生命周期方法

    生命周期是指一个小程序从创建到销毁的一系列过程 在小程序中 ,通过App()来注册一个小程序 ,通过Page()来注册一个页面 先来看一张小程序项目结构 从上图可以看出,根目录下面有包含了app.js ...

  6. Fragment与Fragment相互切换之间的生命周期方法

    Fragment 1 切换到 Fragment 2时生命周期变化 1.通过 add hide show 方式来切换 Fragment Fragment1 的生命周期变化为:onCreate().onC ...

  7. Spring(十二):IOC容器中Bean的生命周期方法

    IOC容器中Bean的生命周期方法 1)Spring IOC容器可以管理Bean的声明周期,Spring允许在Bean生命周期的特定点执行定制的任务. 2)Spring IOC容器对Bean的生命周期 ...

  8. 生命周期方法调用,以及在onStop()方法中处理草稿信息

    生命周期方法调用顺序 1. 从会话列表界面跳转到信息列表界面. 07-17 17:29:18.718: I/txrjsms(19370): MessageListActivity.onCreate 0 ...

  9. Android之Activity界面跳转--生命周期方法调用顺序

    这本是一个很基础的问题,很惭愧,很久没研究这一块了,已经忘得差不多了.前段时间面试,有面试官问过这个问题.虽然觉得没必要记,要用的时候写个Demo,打个Log就清楚了.但是今天顺手写了个Demo,也就 ...

随机推荐

  1. 定义一个复数类Complex

    #include<iostream> #include<math.h> using namespace std; class Complex{ public: Complex( ...

  2. Shrio Demo

    package com.atguigu.shiro.helloworld; import org.apache.shiro.SecurityUtils; import org.apache.shiro ...

  3. STM32F407 串口通信:分类&常见接口 个人笔记

    串行通信的分类 常见串行通信接口 STM32 UART STM32串口异步通信需要定义的参数: ① 起始位 ② 数据位(8位或者9位) ③ 奇偶校验位(如果有的话是第9位) ④ 停止位(1,15,2位 ...

  4. [luoguP2885] [USACO07NOV]电话线Telephone Wire(DP + 贪心)

    传送门 真是诡异. 首先 O(n * 100 * 100) 三重循环 f[i][j] 表示到第 i 个柱子,高度是 j 的最小花费 f[i][j] = min(f[i - 1][k] + abs(k ...

  5. SQL SERVER 2012 第三章 T-SQL 基本语句 group by 聚合函数

    select Name,salesPersonID From Sales.store where name between 'g' and 'j' and salespersonID > 283 ...

  6. 洛谷—— P3370 【模板】字符串哈希

    P3370 [模板]字符串哈希 题目描述 如题,给定N个字符串(第i个字符串长度为Mi,字符串内包含数字.大小写字母,大小写敏感),请求出N个字符串中共有多少个不同的字符串. 友情提醒:如果真的想好好 ...

  7. Ubuntu 16.04升级4.7.0内核后导致Compiz奔溃,问题:compiz[4852]: segfault at 48 ip 00007f88cae087f0 sp 00007ffce354c268 error 4 in libscale.so

    由于硬件的驱动支持问题,升级4.7.0的内核主要是为了能使用Intel HD Graphics 630驱动,但是也出现了相关问题,比如Compiz的特效导致桌面上如果有多个相同程序启动,然后再次点击时 ...

  8. 消息队列RabbitMQ使用教程收集

    学习应该要系统,最好的方式是看书. RabbitMQ最权威的教程应该参考官方文档. 下面是收集的一些教程: 官方: https://www.rabbitmq.com/getstarted.html h ...

  9. 源码SDWebImage

    源码来源:https://github.com/rs/SDWebImage 版本: 3.7 SDWebImage是一个开源的第三方库,它提供了UIImageView的一个分类,以支持从远程服务器下载并 ...

  10. Visual studio 2008 的语法高亮插件 WordLight

    前段时间一直在使用matlab,今天需要使用vs2008,而用惯了matlab,习惯了其中一项选中变量高亮的设置,突然回来使用VS,感到各种不适应,顿时想到了一个词:矫情 呵呵,于是在网上找各种插件, ...