andriod-api翻译(一)--activity

Activities

An Activity is an application component thatprovides a screen with which users can interact in order to do something, suchas dial the phone, take a photo, send an email, or view a map. Each activity isgiven a window in which to draw its user interface. The window typically fillsthe screen, but may be smaller than the screen and float on top of otherwindows.

activity是提供一个用户可以交互的屏幕应用组件,像拨打电话、照相、发邮件或看地图。每个 activity被给予一个窗口来绘制一个用户界面。那个窗口通常会充满屏幕,但是也可能会比屏幕小,而且浮在其他窗口上。

An applicationusually consists of multiple activities that arelooselybound to each other. Typically, one activity in an application is specified as the"main" activity, which is presented to the user when launching theapplication for the first time. Each activity can then start another activityin order to perform different actions. Each time a new activity starts, the previous activity is stopped, butthe system preserves the activity in a stack (the "back stack"). When a new activity starts, it is pushed onto the backstack andtakes user focus.The back stack abides to the basic "last in, first out" stackmechanism, so, when the user is done with the current activity and presses theBack button, it is popped from thestack (and destroyed) and the previous activity resumes.(The back stack is discussed more in theTasks and BackStack document.)

一个应用通常包含多个互相松散绑定的activities通常,在一个应用中一个activity被规定为主activity,主activity就是第一次启动应用程序时呈现给用户的。每一个activity随后都可以通过启动其他的activity来执行不同的操作。每回一个新的activity启动时,之前的activity被关闭,但是之前的activity被系统保留在一个栈中(返回栈)。当一个新的activity启动时,它被压入返回栈中并获得用户焦点。返回栈遵循基本的“后进先出”原则,所以当用户已经处理完当前activity而且点击返回按钮时,当前activity从栈中弹出(并销毁),先前的activity恢复。(返回栈在Tasks and Back Stack档中有更多讨论。

When an activityis stopped because a new activity starts, it is notified of this change instate through the activity's lifecycle callback methods. There are severalcallback methods that anactivity might receive, due to a change in its state—whether the system iscreating it, stopping it, resuming it, or destroying it—and each callbackprovides you the opportunity toperform specific work that'sappropriate to that state change. For instance, when stopped, your activityshould release any large objects, such as network or database connections. Whenthe activity resumes, you can reacquire the necessary resources and resumeactions that were interrupted. These state transitions are all part of theactivity lifecycle.

当一个activity由于一个新的activity启动而停止时,它通过activity的生命周期的回调方法来通知这种状态的改变。一个activity可能会接收几个不同的回调方法,这取决于它状态的改变——无论系统正在创建它,停止它,恢复它,和销毁它——并且每个回调方法提供一个机会,让你根据相应的状态的改变,来做一些特定的工作。比如,当停止时,你的activity应释放任何的大对象,比如网络或者数据库连接。当一个activity恢复时,你可以重新请求必要的资源并恢复被中断的操作。

The rest of thisdocument discusses the basics of how to build and use an activity, including acomplete discussion of how the activity lifecycle works, so you can properlymanage the transition between various activity states.

本文档的其余部分,讨论怎么去构建和使用activity的的基础,包括完全讨论activity的生命周期是如何工作的,这样你能相应的管理各种activity状态的转换。


Class Overview 类概述

An activity is a single, focused thing that the user can do. Almostall activities interact with the user, so the Activity class takes care ofcreating a window for you in which you can place your UI with setContentView(View).While activities are often presented to the user as full-screen windows, theycan also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embeddedinside of another activity (using ActivityGroup). There are two methods almost all subclasses of Activitywill implement:

一个activity是一个单独的,获得用户关注的。几乎所有的activities与用户交互,所以Activity类负责创建窗口,在窗口中你可以通过setContentView(View)来放置UI控件。尽管Activities经常以全屏显示给用户,它也可以有其他的用法:像浮动窗口(通过带windwosIsFloating集的主题)或内置在其他activityactivity(通过ActivityGroup设置)。有两个方法大部分Activity子类都会实现:

·        onCreate(Bundle) is where you initialize your activity. Most importantly, hereyou will usually call setContentView(int) with a layout resource defining your UI, and usingfindViewById(int) to retrieve the widgets in that UI that you need tointeract with programmatically.

·        OnCreate(Bundle)用于初始化Activity。最重要的是,在这里一般通过一个定义你UIlayout资源来调用setContentView,用findViewById(int)获取你需要以编程的方式来交互的UI控件。

·        onPause() is where you deal with the user leaving your activity. Mostimportantly, any changes made by the user should at this point be committed(usually to theContentProvider holding the data).

·        OnPause用于处理用户退出Avtivity。最重要的是,此刻任何用户所做的修改的应该被提交(通常由ContentProvider保存相应的数据)。

Developer Guides 开发者指南

The Activity class is an important partof an application's overall lifecycle, and the way activities are launched andput together is a fundamental part of the platform's application model. For adetailed perspective on the structure of an Android application and howactivities behave, please read the ApplicationFundamentals and Tasks and BackStack developer guides.

Activity类是一个应用程序整个生命周期很重要的一部分,activity的加载和组成的方法是平台的应用模型的基础部分。如果想详细了解Android应用的结构和activities运作方式,可以阅读ApplicationFundamentalsTasks and Back Stack开发者指南

You can also find a detailed discussion about how to create activitiesin the Activities developer guide.

你也可以在Activities开发者指南中找到详细的如何创建activities讨论。

Activity Lifecycle  Activity生命周期

Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top ofthe stack and becomes the running activity -- the previous activity alwaysremains below it in the stack, and will not come to the foreground again untilthe new activity exits.

系统中的活动窗口用Activity堆栈管理。当一个新的activity被启动时,它被放置在堆栈的顶部,并且变成正在运行的activity --先前的activity在堆栈中始终保持在它的下面,直到新的activity退出时它才会出现在最前面。

一个activity基本上有四种状态:

An activity has essentially four states:

·        If an activity inthe foreground of the screen (at the top of the stack), it is active or running.

·        如果一个activity在屏幕的最前面(在堆栈的顶部),它是活着的或正在运行的。

·        If an activity haslost focus but is still visible (that is, a new non-full-sized or transparentactivity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains allstate and member information and remains attached to the window manager), butcan be killed by the system in extreme low memory situations.

·        如果一个activity已经失去焦点,但仍然可见(即,一个新的非全屏的或明显的activity在你的activity前面),它已暂停。一个暂停的activity是完全活着的(它保持所有状态和成员信息并保持连接到窗口管理器),但可能在极端低内存情况下被系统杀死。

·        If an activity iscompletely obscured by another activity, it is stopped. It still retains all state and member information,however, it is no longer visible to the user so its window is hidden and itwill often be killed by the system when memory is needed elsewhere.

·        如果一个activity是由另一个activity完全遮蔽,它已停止。它仍然保留了所有状态和成员信息,但是,它不再对用户可见,所以它的窗口被隐藏,但在系统需要额外内存来支持其他应用程序的情况下经常被系统杀死。

·        If an activity ispaused or stopped, the system can drop the activity from memory by eitherasking it to finish, or simply killing its process. When it is displayed againto the user, it must be completely restarted and restored to its previousstate.

·        如果一个activity是暂停或停止时,系统要么要求它完成,或者干脆杀死它的进程来释放该activity的内存空间。当它再次显示给用户时,它必须完全重新启动并恢复到它原来的状态。

The following diagram shows the important state paths of an Activity.The square rectangles represent callback methods you can implement to performoperations when the Activity moves between states. The colored ovals are majorstates the Activity can be in.

下图显示了一个activity的重要状态的路径。矩形表示当activity转移状态时,你可以用来执行操作的回调方法。彩色的椭圆是一个activity主要的状态。

There are three key loops you may be interested in monitoring withinyour activity:

你可能在监控你的activity时对三个关键的环路感兴趣:

·        The entire lifetime of an activity happensbetween the first call to onCreate(Bundle) through to a single final call to onDestroy(). An activity will do all setup of "global" statein onCreate(), and release all remaining resources in onDestroy(). For example,if it has a thread running in the background to download data from the network,it may create that thread in onCreate() and then stop the thread inonDestroy().

·        从第一次调用的onCreateBundle)到最终调用onDestroy()方法之间就是一个activity的整个生命周期。一个activity会在onCreate()中设置所有的“全局”状态,在onDestroy()中释放所有的剩余的资源。例如,如果它在后台运行一个线程,这个线程是从网络下载数据,它可以在onCreate()中创建该线程,然后onDestroy()中停止该线程。

·        The visible lifetime of an activity happensbetween a call to onStart() until a corresponding call to onStop(). During this time the user can see the activity on-screen,though it may not be in the foreground and interacting with the user. Betweenthese two methods you can maintain resources that are needed to show theactivity to the user. For example, you can register a BroadcastReceiver in onStart() to monitor for changes that impact your UI,and unregister it in onStop() when the user no longer sees what you aredisplaying. The onStart() and onStop() methods can be called multiple times, asthe activity becomes visible and hidden to the user.

·        一个activity的可视生命周期从调用onStart(),直到调用一个相应的onStop()。在此期间,用户可以在屏幕上看到该activity,尽管它可能不在最前面,也不和用户交互。在调用这两种方法期间你就可以保持所需要的资源,以显示activity给用户。例如,你可以在onStart()中注册一个BroadcastReceiver来监视你的UI的变化,并在onStop()中注销它,当用户不再看到你显示什么时。该onStart()和OnStop()方法可以被调用多次,来使activity变得可见和对用户隐藏。

·        The foreground lifetime of an activityhappens between a call to onResume() until a corresponding call to onPause(). During this time the activity is in front of all otheractivities and interacting with the user. An activity can frequently go betweenthe resumed and paused states -- for example when the device goes to sleep, whenan activity result is delivered, when a new intent is delivered -- so the codein these methods should be fairly lightweight.

·        一个activity的前台生命周期从调用onResume(),直到调用一个相应的onPause()。在此期间,该activity是在所有其他activity前面与用户交互。一个activity可以频繁在恢复和暂停状态之间转换 - 例如当设备进入睡眠状态时,当一个activity的结果被传递时,当一个新的intent被传递时 - 所以在这些方法的代码应该是相当轻量级的。

The entirelifecycle of an activity is defined by the following Activity methods. All ofthese are hooks that you can override to do appropriate work when the activitychanges state. All activities will implement onCreate(Bundle) to do their initial setup; many will also implement onPause() to commit changes to data and otherwise prepare to stopinteracting with the user. You should always call up to your superclass whenimplementing these methods.

一个activity的整个生命周期是由以下Activity方法定义的。当activity状态改变时,你可以重写所有这些方法来做适当的工作。所有activity将实现onCreateBundle)方法做他们的初始设置;许多activity也将实现onPause()方法来提交修改的数据,否则准备停止与用户交互。实现这些方法时,您应该总是通知你的父类。

onCreate()

Called when the activity is first created.This is where you should do all of your normal static set up: create views,bind data to lists, etc. This method also provides you with a Bundle containingthe activity's previously frozen state, if there was one.

Always followed by onStart().

第一次创建activity时调用。在这个方法中你应该做的所有的正常的静态设置包括:创建视图,绑定数据到列表,等等。这种方法也给你提供了一个Bundle,包含此activity先前冻结的状态,如果有一个冻结的状态的话。之后总是会调用onStart()方法。

onRestart()

Called after your activity has beenstopped, prior to it being started again.

Always followed by onStart()

当你的activity已经停止,被再次启动之前调用。之后总是会调用onStart()方法。

onStart()

Called when the activity is becomingvisible to the user.

Followed by onResume() if the activitycomes to the foreground, or onStop() if it becomes hidden.

activity对用户可见时调用。如果此activity到前台时之后会调用onResume()方法。如果它被隐藏之后会调用onStop()方法。

onResume()

Called when the activity will startinteracting with the user. At this point your activity is at the top of theactivity stack, with user input going to it.

Always followed by onPause().                       

activity开始与用户交互时调用。此时你的activity是在Activity堆栈的顶部,用户将要在它中输入东西。之后会调用onPause()方法。

onPause()

Called when the system is about to startresuming a previous activity. This is typically used to commit unsaved changesto persistent data, stop animations and other things that may be consuming CPU,etc. Implementations of this method must be very quick because the nextactivity will not be resumed until this method returns.

Followed by either onResume() if the activityreturns back to the front, or onStop() if it becomes invisible to the user.

当系统即将开始恢复以前的activity时调用。这通常用于提交对持久化数据的未保存的更改,停止动画和停止其他可能消耗CPU的事情。此方法的实现非常快,因为接下来的activity直到该方法返回才能恢复,否则将不会恢复。

如果activity返回到前面之后会调用onResume()方法,如果它变得对用户不可见之后会调用onStop()方法。

onStop()

Called when the activity is no longervisible to the user, because another activity has been resumed and is coveringthis one. This may happen either because a new activity is being started, anexisting one is being brought in front of this one, or this one is beingdestroyed.

Followed by either onRestart() if this activity iscoming back to interact with the user, or onDestroy() if this activity isgoing away

activity不再对用户可见时调用,因为另一个activity已经被恢复并且覆盖这个activity。这种情况发生可能是因为一个新的activity正在被启动,现有的activity将被带入在这一个的前面,或这一个activity正在被破坏。如果activity返回到前面与用户交互之后会调用onStart()方法,如果它要离开之后会调用onDestroy()方法。

onDestroy()

The finalcall you receive before your activity is destroyed. This can happen eitherbecause the activity is finishing (someone called finish() on it, or because the system is temporarily destroyingthis instance of the activity to save space. You can distinguish between thesetwo scenarios with the isFinishing()method.

你的activity被破坏前收到的最后调用。这发生可能是因为activity正在完成(有人叫finish()),或因为系统暂时正在销毁该activity的实例以节省空间。你可以用isFinishing )方法区别这两种情况。

ProcessLifecycle 进程生命周期

The Android system attempts to keep application processaround foras long as possible, but eventually will need to remove old processes whenmemory runs low. As described in Activity Lifecycle, the decision about which process to remove is intimatelytied to the state of the user's interaction with it. In general, there are fourstates a process can be in based on the activities running in it, listed herein order of importance. The system will kill less important processes (the lastones) before it resorts tokilling more important processes (the first ones).

Android系统试图尽量的延长应用进程的的周期,但是在内存不足时最终是需要移除旧的进程。正如在Activity Lifecycle生命周期所表述的那样,移除哪个进程的决策与用户和它的交互状态有关。一般基于运行其中的activity一个进程可有4个状态,按照重要程度列表如下。系统会在不太重要的进程(the last ones) 诉诸于杀掉更重要的进程(the first ones)前杀掉它。

The foregroundactivity (the activity at the top of the screen that the user is currentlyinteracting with) is considered the most important. Its process will only bekilled as a last resort, if it uses more memory than is available on thedevice. Generally at this point the device has reached a memory paging state, sothis is required in order to keep the user interface responsive.

前台activity(用户正在交互的在屏幕最上面的activity是最重要的。如果当他需要的内存超过当前设备的可能的允许程度时,系统将会把它的进程杀掉作为最后的选择。通常在这时设备已经达到存储分页状态,所以需要kille这个process以便使得用户界面可以响应用户的操作。

A visible activity (anactivity that is visible to the user but not in the foreground, such as onesitting behind a foreground dialog) is considered extremely important and willnot be killed unless that is required to keep the foreground activity running.

可见activity(用户保持可见但不在前台的activity,例如一个在前台对话的之后的activity)是非常重要的而且只有在为了保持前台process正常运行的情况下才会kille这个process

A background activity (anactivity that is not visible to the user and has been paused) is no longercritical, so the system may safely kill its process to reclaim memory for otherforeground or visible processes. If its process needs to be killed, when theuser navigates back to the activity (making it visible on the screen again),itsonCreate(Bundle) method will be called with the savedInstanceState it hadpreviously supplied in onSaveInstanceState(Bundle) so that it can restart itself in the same state as theuser last left it.

一个后台activityactivity是用户不可见的并且已暂停)不再那么重要,因此系统可以安全地杀死它的进程来回收内存供其他前台或可见的进程使用。如果他的进程需要被杀死,而当用户导航回到该activity(使它在屏幕上再次出现),他的onCreateBundle)方法会调用它以前在onSaveInstanceStateBundle)中提供的savedInstanceState,使其能够重新启动到上次用户离开它时相同的状态。

An empty process is onehosting no activities or other application components (such as Service or BroadcastReceiver classes). These are killed very quickly by the system asmemory becomes low. For this reason, any background operation you do outside ofan activity must be executed in the context of an activity BroadcastReceiver orService to ensure that the system knows it needs to keep your process around.

一个空的进程,没持有任何activity,也没有其他应用程序组件(如服务或BroadcastReceiver类)。当内存变低时,这些进程很快被系统杀害。出于这个原因,在一个activity之外你做的任何后台操作必须在activity BroadcastReceiver的或服务的上下文中执行,以确保系统知道它需要保持你的进程运行。

Sometimes an Activity may need to do a long-runningoperation that exists independently of the activity lifecycle itself. Anexample may be a camera application that allows you to upload a picture to aweb site. The upload may take a long time, and the application should allow theuser to leave the application will it is executing. To accomplish this, yourActivity should start a Service in which the upload takes place. This allows the system toproperly prioritize your process (considering it to be more important than othernon-visible applications) for the duration of the upload, independent ofwhether the original activity is paused, stopped, or finished.

有时候,一个Activity可能需要做一个长时间运行的操作,且这个操作独立于activity的生命周期。例如一个摄像头应用程序,允许您将图片上传到网站。上传可能需要很长的时间,并且应用程序应该允许用户离开应用程序,而上传还会被执行。要做到这一点,你的Activity应该开启一个服务,在这个服务里完成上传。这使得系统优先考虑你的进程(考虑到它比其他不可见应用更重要),不管原来的activity是暂停,停止或完成。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
系统根据B/S,即所谓的电脑浏览器/网络服务器方式,运用Java技术性,挑选MySQL作为后台系统。系统主要包含对客服聊天管理、字典表管理、公告信息管理、金融工具管理、金融工具收藏管理、金融工具银行卡管理、借款管理、理财产品管理、理财产品收藏管理、理财产品银行卡管理、理财银行卡信息管理、银行卡管理、存款管理、银行卡记录管理、取款管理、转账管理、用户管理、员工管理等功能模块。 文中重点介绍了银行管理的专业技术发展背景和发展状况,随后遵照软件传统式研发流程,最先挑选适用思维和语言软件开发平台,依据需求分析报告模块和设计数据库结构,再根据系统功能模块的设计制作系统功能模块图、流程表和E-R图。随后设计架构以及编写代码,并实现系统能模块。最终基本完成系统检测和功能测试。结果显示,该系统能够实现所需要的作用,工作状态没有明显缺陷。 系统登录功能是程序必不可少的功能,在登录页面必填的数据有两项,一项就是账号,另一项数据就是密码,当管理员正确填写并提交这二者数据之后,管理员就可以进入系统后台功能操作区。进入银行卡列表,管理员可以进行查看列表、模糊搜索以及相关维护等操作。用户进入系统可以查看公告和模糊搜索公告信息、也可以进行公告维护操作。理财产品管理页面,管理员可以进行查看列表、模糊搜索以及相关维护等操作。产品类型管理页面,此页面提供给管理员的功能有:新增产品类型,修改产品类型,删除产品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值