美文网首页
2019-04-08 Introduction to Activ

2019-04-08 Introduction to Activ

作者: Denholm | 来源:发表于2019-04-08 16:14 被阅读0次

    Introduction to Activities

    The Activity class is a crucial component of an Android app, and the way activities are launched and put together is a fundamental part of the platform's application model. Unlike 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.

    Activity是Android应用中一个十分重要的组件,并且它的启动和组合方式是应用模式平台的基本组成部分。与使用main()方法启动应用程序的编程范例不同,Android系统通过调用与活动实例生命周期的特定阶段对应的特定回调方法来启动活动实例中的代码。

    This document introduces the concept of activities, and then provides some lightweight guidance about how to work with them. For additional information about best practices in architecting your app, see Guide to App Architecture.
    该文档介绍的Activity的概念,并且提供了一些关于如何让它们工作的轻量级的指导,有关应用程序架构最佳实践的更多信息,请阅读 Guide to App Architecture.

    The concept of activities

    Activity概念
    The mobile-app experience differs from its desktop counterpart in that a user's interaction with the app doesn't always begin in the same place. Instead, the user journey often begins non-deterministically. For instance, if you open an email app from your home screen, you might see a list of emails. By contrast, if you are using a social media app that then launches your email app, you might go directly to the email app's screen for composing an email.
    移动应用程序体验与桌面应用程序的不同之处在于,用户与应用程序的交互并不总是在同一位置开始。相反,用户往往是从非确定性的地方开始旅程。例如,如果你从首页打开一个邮件app,你可能会看到一个邮件列表。相比之下,如果你使用的是社交媒体应用程序,然后启动你的电子邮件应用程序,你可以直接进入电子邮件应用程序的屏幕撰写电子邮件。
    The [Activity](https://developer.android.google.cn/reference/android/app/Activity.html) class is designed to facilitate this paradigm. When one app invokes another, the calling app invokes an activity in the other app, rather than the app as an atomic whole. In this way, the activity serves as the entry point for an app's interaction with the user. You implement an activity as a subclass of the [Activity](https://developer.android.google.cn/reference/android/app/Activity.html) class.
    Activity类被设计为促进这样的范式。当一个app调用另一个app时,调用app去唤醒另一个app里面的Activity,而不是把app当作一个原子整体调用。在这种方式下,Activity就成为app与用户交互的入口点。你可以实现一个Activity的子类(去做自定义的操作)。
    An activity provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app. For instance, one of an app’s activities may implement a Preferences screen, while another activity implements a Select Photo screen.
    Activity提供app绘制其用户界面的窗口。这个窗口通常充满屏幕,但也可能小于屏幕并浮动在其他窗口之上。通常,一个活动在应用程序中实现一个屏幕。例如,app的一个Activity可以实现首选项屏幕,而另一个Activity可以实现选择照片屏幕。
    Most apps contain multiple screens, which means they comprise multiple activities. Typically, one activity in an app is specified as the main activity, which is the first screen to appear when the user launches the app. Each activity can then start another activity in order to perform different actions. For example, the main activity in a simple e-mail app may provide the screen that shows an e-mail inbox. From there, the main activity might launch other activities that provide screens for tasks like writing e-mails and opening individual e-mails.
    大多数app包含多个屏幕,这意味着它包含多个Activity。通常,app有一个Activity被指定为主Activity,当用户启动app时它是第一个显示的屏幕。然后,每个Activity可以启动另一个Activity去执行不同的操作。简单电子邮件应用程序中的主Activity可能提供显示电子邮件收件箱的屏幕。从那里,主Activity可能会启动其他活动,为诸如编写电子邮件和打开单个电子邮件等任务提供屏幕。
    Although activities work together to form a cohesive user experience in an app, each activity is only loosely bound to the other activities; there are usually minimal dependencies among the activities in an app. In fact, activities often start up activities belonging to other apps. For example, a browser app might launch the Share activity of a social-media app.
    尽管Activity在app中共同工作形成一种紧密的用户体验,但是每个Activity仅仅是与其他的Activity松散的绑定在一起;app中的Activity通常存在最小的依赖关系。事实上,Activity经常启动属于其他app的Activity。例如,浏览器app可能会启动社交媒体app的共享Activity。
    To use activities in your app, you must register information about them in the app’s manifest, and you must manage activity lifecycles appropriately. The rest of this document introduces these subjects.
    为了在你的app中使用Activity,你必须在app的清单文件中注册他们的有关信息,并且你必须适当地管理Activity的生命周期。本文档的其余部分介绍了这些主题。

    相关文章

      网友评论

          本文标题:2019-04-08 Introduction to Activ

          本文链接:https://www.haomeiwen.com/subject/btguiqtx.html