Starting an Activity 开启一个活动

Starting an Activity

开启一个活动

Previous NextGet
 started

This lesson teaches you to

这个课程教你去了解以下:

  1. Understand the Lifecycle Callbacks       理解生命周期回调
  2. Specify Your App‘s Launcher Activity    
    指定应用程序的启动活动
  3. Create a New Instance                           创建一个新的案例
  4. Destroy the Activity                                 销毁这个活动

You should also read

Try it out

Download the demo

ActivityLifecycle.zip

Unlike other programming paradigms in which apps are launched with a main() method, the Android system initiates code in an
Activity instance by invoking specific callback methods that correspond to specific stages of its lifecycle. There is a sequence of callback methods
that start up an activity and a sequence of callback methods that tear down an activity.

与其他的编程范式即应用程序带有一个main()方法的范式不同,Android系统在特定的生命周期阶段通过调用特定的回调方法在一个Activity案例中启动代码。有一系列回调方法,来启动一个活动以及利用一系列回调方法来拆分一个活动。

This lesson provides an overview of the most important lifecycle methods and shows you how to handle the first lifecycle callback that creates a new instance of your activity.

这节课提供了一个有关于最重要的声明周期方法的概述,向您展示如何处理您所创建新的实例的活动的第一个生命周期回调,。

Understand the Lifecycle Callbacks      理解生命周期回调



During the life of an activity, the system calls a core set of lifecycle methods in a sequence similar to a step pyramid. That is, each stage of the activity lifecycle is a separate step on the pyramid. As the system creates a new activity instance, each
callback method moves the activity state one step toward the top. The top of the pyramid is the point at which the activity is running in the foreground and the user can interact with it.

在一个活动的生命过程中,生命周期方法的系统调用呈现出一组核心序列类似于阶梯金字塔的形式。即活动生命周期的每个阶段都是金字塔上独立的一步。系统创建一个新的活动实例时,每个回调方法是向顶端移动一步。金字塔的顶部是在前台运行,用户可以与之交互的点活动。

As the user begins to leave the activity, the system calls other methods that move the activity state back down the pyramid in order to dismantle the activity. In some cases, the activity will move only part way down the pyramid and wait (such as when the
user switches to another app), from which point the activity can move back to the top (if the user returns to the activity) and resume where the user left off.

当用户开始离开这个活动,系统调用其他方法将活动状态的活动掉回到金字塔来拆分活动。在某些情况下,该活动将只沿着金字塔移动一部分或者等待(如当用户切换到另一个应用程序),这个点的活动可以从用户离开离开的地方返回顶部(如果用户返回到活动)和继续。

Figure 1. A simplified illustration of the Activity lifecycle, expressed as a step pyramid. This shows how, for every callback used to take the activity a step toward the Resumed state at the top, there‘s a callback method
that takes the activity a step down. The activity can also return to the resumed state from the Paused and Stopped state.

一个活动的生命周期的简化的例子,表现为一个阶梯金字塔。这表明,每个回调用于把活动一步恢复状态在顶部,有一个回调方法,以活动下台。活动还可以回到恢复状态暂停和停止状态。

Depending on the complexity of your activity, you probably don‘t need to implement all the lifecycle methods. However, it‘s important that you understand each one and implement those that ensure your app behaves the way users expect. Implementing your activity
lifecycle methods properly ensures your app behaves well in several ways, including that it:

基于你的活动的复杂性,您可能不需要实现所有生命周期方法。但是,重要的是你理解每一个那些确保应用程序的行为用户期望的方式和实施。实现你的正常活动生命周期方法可以在几个方面确保你的应用程序的行为,包括:

  • Does not crash if the user receives a phone call or switches to another app while using your app.

如果用户收到一个电话或切换到另一个应用程序在使用你的应用程序不会崩溃。

  • Does not consume valuable system resources when the user is not actively using it

当用户使用它时,不消耗宝贵的系统资源

  • Does not lose the user‘s progress if they leave your app and return to it at a later time.

如果他们在一会儿的时间之间离开你的应用程序并返回它,不失去用户的进程。

  • Does not crash or lose the user‘s progress when the screen rotates between landscape and portrait orientation.

在横向和纵向之间当屏幕旋转方向时,不崩溃或失去用户的进程。

Starting an Activity 开启一个活动

时间: 2024-08-13 04:25:20

Starting an Activity 开启一个活动的相关文章

Managing the Activity Lifecycle 管理活动的生命周期

Managing the Activity Lifecycle 管理活动的生命周期 Previous         Next         Get started Dependencies and prerequisites 依赖和先决条件 How to create an Android project (see Creating an Android Project) 如何创建一个Android项目(参见创建一个Android项目) You should also read 你也应该阅读

Android官方入门文档[12]启动一个活动

Android官方入门文档[12]启动一个活动 Starting an Activity启动一个活动 This lesson teaches you to1.Understand the Lifecycle Callbacks2.Specify Your App's Launcher Activity3.Create a New Instance4.Destroy the Activity 这节课教你1.了解生命周期回调2.指定您的应用程序的启动活动3.创建一个新实例4.销毁活动 You sho

Recreating an Activity 重新创建一个活动

There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses theBack button or your activity signals its own destruction by calling finish(). The system may also destroy your activity if it's

返回数据给上一个活动

我们都知道,android开发中一个活动跳转时是可以带数据传递给下一个活动的,那么能不能够返回数据给上一个活动呢?答案是肯定的.不过不同的是,返回上一个活动只需要按一下Back键就可以了,并没有一个用于启动活动Intent来传递数据.通过查阅文档你会发现,Activity中还有一个startActivityForResult()方法也是用于启动活动的,但这个方法期望在活动销毁的时候能返回一个结果给上一个活动.毫无疑问,这就是我们所需要的. startActivityForResult()方法接收

Android学习笔记(二)——探究一个活动

//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 活动(Activity)是最容易吸引到用户的地方了,它是一种可以包含用户界面的组件,主要用于和用户进行交互.一个应用程序中可以包含零个或多个活动.活动是Android四大组件之一,下面我们来探究一个活动. 1.创建一个活动: 我们可以按照学习笔记(一)中的流程创建了一个活动,创建之后可以看见IDE已经为我们写好的默认onCreate()方法: 默认onCreate()方法非常简单,就是调用了父类的 onCreate(

starting an activity

开启一个activity 不像其他应用程序是在main方法中启动的,android系统启动一个activity实例是通过唤醒一个符合生命周期特定状态的回调方法来实现的.这里有一系列的回调方法去开启一个activity也有一系列的回调方法去销毁一个activity. 本节课提供了所有重要生命周期函数的概述并且告诉你在创建一个新的activity实例时如何去处理生命周期函数.

[Android5 系列—] 2. 开始另外一个活动

前言 承接上一篇, 接下来介绍点击 Send 按钮后的操作. 响应发送按钮 1.  res/layout 目录下.打开 activity_my.xml 2.  在<Button> 元素里面,添加属性  android:onClick res/layout/activity_my.xml <Button android:layout_width="wrap_content" android:layout_height="wrap_content" a

intent传递数据和返回数据给上一个活动

startActivityForResult与startActivity的不同之处在于: 1.startActivity( ) 仅仅是跳转到目标页面,若是想跳回当前页面,则必须再使用一次startActivity( ). 2.startActivityForResult( ) 可以一次性完成这项任务,当程序执行到这段代码的时候,假若从T1Activity跳转到下一个Text2Activity,而当这个Text2Activity调用了finish()方法以后,程序会自动跳转回T1Activity,

使用http-server开启一个本地服务器

前言 在写前端页面中,经常会在浏览器运行HTML页面,从本地文件夹中直接打开的一般都是file协议,当代码中存在http或https的链接时,HTML页面就无法正常打开,为了解决这种情况,需要在在本地开启一个本地的服务器. 本文是利用node.js中的http-server,开启本地服务,步骤如下: 1 下载node.js 官网地址: https://nodejs.org 下载完成后在命令行输入命令$ node -v以及$ npm -v检查版本,确认是否安装成功. 2 下载http-server