Creating an Activity创建一个Activity

  • Android,activity,翻译,中文,英文,官方文档,

【Binkery友情提示,翻译纯属个人行为,本人英语四级没过,参考需谨慎!!!】

To create an activity, you must create a subclass of Activity (or an existing subclass of it).

创建一个 activity,必须创建一个 Activity 的子类(或者一个已经存在的 Activity 的子类)。总之,这个类 肯定是 Activity 的子类。

In your subclass, you need to implement callback methods that the system calls when the activity transitions between various states of its lifecycle, such as when the activity is being created, stopped, resumed, or destroyed.

在你的子类里,你需要实现回调方法,当 activity 在它的生命周期的不同(various)状态之间转换 (transition)的时候,系统会调用这些回调方法,比如 activity 被创建,停止,恢复或者销毁。

The two most important callback methods are:

有两个很重要的回调方法

onCreate()

You must implement this method. The system calls this when creating your activity.

你必须实现这个方法,系统在创建你的activity的时候调用这个方法。

Within your implementation, you should initialize the essential components of your activity.

在你实现的方法内,你可以初始化这个 activity 的主要(essential)的控件(component)。

Most importantly, this is where you must call setContentView() to define the layout for the activity's user interface.

最重要的,在这个方法里,你需要调用 setContentView() 来定义(define)这个 activity 的用户交互界面的布局。

onPause()

The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed).

系统会首先调用这个方法来表示用户正在离开你的 activity(虽然它并不总是意味着这个activity正在被销毁 )

This is usually where you should commit any changes that should be persisted beyond the current user session (because the user might not come back).

在这里,你可以提交一些改变,这些改变可以一直被持续着,超出了当前的用户会话(因为用户可能不会再回来)

There are several other lifecycle callback methods that you should use in order to provide a fluid user experience between activities and handle unexpected interruptions that cause your activity to be stopped and even destroyed.

还有一些其他的生命周期的回调方法,你可以使用它们在 activity 之间来提供一个流畅(fluid)的用户体验 (user experience)和处理一些意外(unexpected)的中断(interruptions),这些中断可能导致你的activity 被停止甚至销毁。

All of the lifecycle callback methods are discussed later, in the section about Managing the Activity Lifecycle.

所有的生命周期的回调方法在后面的Activity的生命周期的章节里将被讨论(discussed)。

返回总目录】 【返回Activity

相关文章

- EOF -

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处,尊重他人劳动。
转载请注明:文章转载自 Binkery 技术博客 [https://binkery.com]
本文标题: Creating an Activity创建一个Activity
本文地址: https://binkery.com/archives/2020.09.01-create-an-activity.html