精华内容
下载资源
问答
  • Activities

    2015-03-17 10:15:42
    Briefly introduce to activities.

    Activities

    An Activity is an application component that provides a screen with which users can interact in order to do something. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.

    An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time. Each activity can then start another activity in order to perform different actions. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack"). When a new activity starts, it is pushed onto the back stack and takes user focus. The back stack abides to the basic "last in, first out" stack mechanism, so, when the user is done with the current activity and presses the Back button, it is popped from the stack (and destroyed) and the previous activity resumes.

    When an activity is stopped because a new activity starts, it is notified of this change in state through the activity's lifecycle callback methods. There are several callback methods that an activity might receive, due to a change in its state --- whether the system is creating it, stopping it, resuming it, or destroying it --- and each callback provides we the opportunity to perform specific work that's appropriate to that state change.


    Creating an Activity

    To create an activity, we must create a subclass of activity(or an exist subclass of it).The tow most important callback methods are:

    onCreate()

    We must implements this method.The system calls this when creating our activity.Most importantly, this is where our must call setContentView() to define the layout for the activity's user interface.

    onPause()

    The system calls this method as the first indicate that the user is leaving our activity(though it does not always mean the activity is being destroyed).This is usually where we should commit any changes that should be persisted beyond the current user session (because the user might not come back).

    Implementing a user interface.

    The user interface for an activity is provided by a hierarchy of views --- objects derived from the View class. Each view controls a particular rectangular space within the activity's window and can respond to user interaction.

    Android provides a number of ready-made views that we can use to design and organize our layout. "Widgets" are views that provide a visual (and interactive) elements for the screen. "Layouts" are views derived from ViewGroup that provide a unique layout model for its child views.

    The most common way to define a layout using views is with an XML layout file saved in our application resources. However, we can also create new Views in our activity code and build a view hierarchy.

    Declaring the activity in the manifest

    We must declare our activity in the manifest in order for it to be accessible to the system. To declare our activity,open our manifest file and add an activity element as a child of the application element.

    There are several other attributes that we can include in this element, to define properties for the activity. The android:name attribute is the only required attribute --- it specifies the class name of the activity. Once we publish our application, we should not change this name.

    Using intent filters

    An <activity> element can also specify various intent filters --- using the <intent-filter> element --- in order to declare how other application components may activate it.

    When we create a new application using the Android SDK tools, the stub activity that's created for us automatically includes an intent filter that declares the activity responds to the "main" action and should be placed in the "launcher" category.

    The <action> element specifies that this is the "main" entry point to the application. The <category> element specifies that this activity should be listed in the system's application launcher (to allow users to launch this activity).

    If we intend for our application to be self-contained and not allow other applications to activate its activities, then we don't need any other intent filters. Only one activity should have the "main" action and "launcher" category. Activities that we don't want to make available to other applications should have no intent filters and we can start them ourself using explicit intents.

    However, if we want our activity to respond to implicit intents that are delivered from other applications (and our own), then we must define additional intent filters for our activity. For each type of intent to which we want to respond, we must include an <intent-filter> that includes an <action> element and, optionally, a  <category> element and/or a <data> element. These elements specify the type of intent to which our activity can respond.


    Starting an activity

    We can start another activity by calling startActivity(), passing it an Intent that describes the activity we want to start. An intent can also carry small amounts of data to be used by the activity that is started.

    When working within our own application, we'll often need to simply launch a known activity. We can do so by creating an intent that explicitly defines the activity we want to start, using the class name.

    However, our application might also want to perform some action. In this case, our application might not have its own activities to perform such actions, so we can instead leverage the activities provided by other applications on the device, which can perform the actions for us.

    Starting an activity for a result

    Sometimes, we might want to receive a result from the activity that we start. In that case, start the activity by calling startActivityForResult() (instead of startActivity()). To then receive the result from the subsequent activity, implement the onActivityResult() callback method. When the subsequent activity is done, it returns a result in an Intent to our onActivityResult() method.

    Shutting down an activity

    We can shut down an activity by calling its finish() method. We can also shut down a separate activity that we previously started by calling finishActivity().

    In most cases, we should not explicitly finish an activity using these methods as Android system manages the life of an activity for us, so we do not need to finish our own activities. Calling these methods could adversely affect the expected user experience and should only be used when we absolutely do not want the user to return to this instance of the activity.


    Managing the activity lifecycle


    An activity can exist in essentially three states:

    resumed:

    The activity is in the foreground of the screen and has user focus.(This state is also sometimes referred to as "running".)

    Pauses:

    Another activity is in the foreground and has focus, but this one is still visible. A paused activity is completely alive (the Activity object is retained in memory, it maintains all state and member information, and remains attached to the window manager), but can be killed by the  system in extremely low memory situations.

    Stopped:

    The activity is completely obscured by another activity(the activity is now in the "background"). A stopped activity is also still alive (the Activity object is retained in memory, it maintains all state and member information, but is not attached to the window manager). However, it is no longer visible to the user and it can be killed by the system when memory is needed elsewhere.

    If an activity is paused or stopped, the system can drop it from memory either by asking it to finish(calling its finish() method), or simply killing its process.When the activity is opened again(after being finished or killed),it must be created all over.

    Implementing the lifecycle callbacks

    When an activity transitions into and out of the different states described above, it is notified through various callback methods.

    Our implementation of these lifecycle methods must always call the superclass implementation before doing any work.

    Taken together, these methods define the entire lifecycle of an activity.By implements these methods, we can monitor three nested loops in the activity lifecycle.

    entire lifetime:

    an activity happens between the call to onCreate() and the call to onDestroy(). Our activity should perform setup of "global" state in onCreate(), and release all remaining resources in onDestroy().

    visible lifetime:

    an activity happens between the call to onStart() and the call to onStop(). During this time, the user can see the activity on-screen and interact with it.

    foreground lifetime:

    an activity happens between the call to onResume() and the call to onPause(). During this time, the activity is in front of all other activities on screen and has user input focus.

    Saving activity state


    When an activity is paused or stopped, the state of the activity is retained. This is true because the activity object is still held in memory when it is paused or stopped----all information about its members and current state is still alive. Thus, any changes the user made within the activity are retained so that when the activity returns to the foreground (when it "resumes"), those changes are still there.

    However, when the system destroys an activity in order to recover memory,the activity object is destroyed,so the system cannot simply resume it when its state intact. Instead, the system must recreate the activity object if the user navigates back to it. Yet, the user is unaware that the system destroyed the activity and recreated it and, thus, probably expects the activity to be exactly as it was. In this situation, we can ensure that important information about the activity state is preserved by implementing an additional callback method that allows we to save information about the state of our activity: onSaveInstanceState().

    The system calls onSaveInstanceState() before making the activity vulnerable to destruction.Then, if the system kills our application process and the user navigates back to our activity,the system recreates the activity and passes the state via bundle to both onCreate() and onRestoreInstanceState(). Using either of these methods, we can extract our saved state from the Bundle and restore the activity state. If there is no state information to restore, then the Bundle passed to us is null (which is the case when the activity is created for the first time).

    There's no guarantee that onSaveInstanceState() will be called before our activity is destroyed, because there are cases in which it won't be necessary to save the state(such as when the user leaves our activity using the Back button,as the user is explicitly closing the activity).It the system calls onSaveInstanceState(), it does so before onStop() and possibly before onPause().

    However, even if we do nothing and do not implement onSaveInstanceState(),some of the activity state is restored by the activity class's default implementation of onSaveInstanceState().Specifically, the default implementation calls the corresponding onSaveInstanceState() method for every view in the layout,which allows each view to provide information about itself that should be saved.The only work required by us is to provide a unique ID(with the android:id attribute) for each widget we want to save its state.If a widget does not have an ID,then the system cannot save its state.

    Although the default implementation of onSaveInstanceState() saves useful information about our activity's UI, we still might need to override it to save additional information (such as member values).

    Because onSaveInstanceState() is not guaranteed to be called, we should use it only to record the transient state of the activity(the state of the UI)---we should never use it to store persistent data. Instead, we should use onPause() to store persistent data(such as data that should be saved to a database)when the user leaves the activity.

    Handling configuration changes

    Some device configurations can change during runtime (such as screen orientation, keyboard availability, and language). When such a change occurs, Android recreates the running activity (the system calls onDestroy(), then immediately calls onCreate()).

    The best way to handle such a restart is to save and restore of our activity using onSaveInstanceState() and onRestoreInstanceState() (or onCreate()).

    Coordinating activities

    When one activity starts another, they both experience lifecycle transitions. The first activity pauses and stops, while the other activity is created. 

    The order of lifecycle callbacks is well defined, particularly when the two activities are in the same process and one is starting the other. Here's the order of operations that occur when Activity A starts Activity B:

    1. Activity A's onPause() method executes.

    2. Activity B's onCreate(),onStart(),and onResume() methods execute in sequence.(Activity B now has user focus.)

    3. Then,if Activity A is no longer visible on screen,its onStop() method executes.

    展开全文
  • Activities fixes

    2021-01-02 09:32:10
    activities' in web was hanging, but the webclient continued to ping every 5 seconds. Now, we only re-try to get activities 5 seconds AFTER the previous call returns successfully. Also add a try/...
  • Staff activities

    2020-12-27 18:37:01
    Due we need quality and activity indicators we need to register our activities during the day (time dedicated for sample prep, for data analysis, etc). We are currently using the scheduler for this ...
  • Missing activities

    2020-12-01 12:50:55
    I have one issue so far though, I seem to be missing activities, particularly older ones but possibly others in between (not sure on this part though). <p>Here is what I think is the relevant part of...
  • <p>I have a problem when syncing recent activities where all earlier activities are removed. That is I can only see the most recent activities in the Fitness Trend. When this occurred once I made a ...
  • Search activities

    2020-12-09 06:14:38
    <div><p>Is there an option to search for specific activities without having to manually scroll through the list looking? If not, can I request it as an enhancement / feature request please.</p><p>该...
  • Disappearing activities

    2020-11-26 04:50:00
    <div><p>When I enter the analysis tab or try to find my activities from any list, they have disappeared or been "whitened out" as shown in my images below. Data appears to remain intact. ...
  • Logging activities

    2020-12-01 18:20:29
    <div><p>Create created_by / updated_by fields for the ...<p>Idea from http://locomotive.vanillaforums.com/discussion/121/logging-activities</p>该提问来源于开源项目:locomotivecms/engine</p></div>
  • Activities?

    2020-11-20 20:46:50
    <div><p>Can you declare activities? <p>I realize the implementation of the activity would not be serverless, and therefore out of the scope of this, but how would you declare an activity task in the ...
  • Activities coordination

    2020-11-26 22:56:11
    <div><p>Here I want to structure my vision of activities around the plugin: <ul><li>Q2 2017: stabilization, crowdfunding obligations</li><li>bug-fixes</li><li>QFes</li><li>dev-stuff (graddle, Jenkins)...
  • <p>For some reason a get_activities call only returns a fraction of my activities. I have about 500 activities in my account, stravalib is only returning 52 for the moment. <p>I say 'for some ...
  • AIE_Activities-源码

    2021-02-08 08:45:46
    AIE_Activities
  • Activities介绍

    2018-03-14 15:06:00
    翻译水平有限,欢迎指正 Activity类是Android应用程序的一个关键组件,activities启动和之间的组合是平台应用模型的一个基本部分。和应用程序通过main()方法启动的编程范式不同,An...

    https://developer.android.google.cn/guide/components/activities/intro-activities.html#java --翻译水平有限,欢迎指正

    Activity类是Android应用程序的一个关键组件,activities启动和之间的组合是平台应用模型的一个基本部分。和应用程序通过main()方法启动的编程范式不同,Android系统通过调用对应于activity生命周期的特定阶段的特定回调方法来启动activity实例中的代码。

    这个文档介绍了Activity的概念,然后提供了一些关于如何使用它们的轻量级指导。

     

    activities概念


      移动应用程序体验与桌面应用程序体验不同之处在于用户与移动应用程序的交互并不总是在同一个地方开始。相反,用户的旅程通常是不确定的。例如,如果你从主屏幕打开一个电子邮件应用程序,你可能会看到一个电子邮件列表。相比之下,如果你使用的是社交媒体应用程序,然后启动你的电子邮件应用程序,你可能会直接进入电子邮件应用程序用来撰写电子邮件的屏幕。

    Activity类的设计目的是为了实现这个模式。当一个应用程序调用另一个应用程序时,调用应用程序会调用另一个应用程序中的某个activity,而不是作为一个原子整体来调用应用程序。这样,activity就成为应用程序与用户交互的入口点。实现activity类的子类来获得activity。

    activity提供了应用程序绘制UI的窗口。这个窗口通常会填充屏幕,但可能比屏幕小,并在其他窗口上浮动。通常,一个activity在应用程序中实现一个屏幕,例如,一个应用程序的一个activity可能实现一个偏好屏幕,而另一个activity实现一个选择的照片屏幕。

    大多数应用程序包含多个屏幕,这意味着它们包含多个activity。通常,应用程序中的一个activity被指定为main activity,这是用户启动应用程序时出现的第一个屏幕,然后每个activity都可以启动另一个activity,以执行不同的操作。例如,一个简单的电子邮件应用程序的main activity可能提供显示电子邮件收件箱的屏幕。从那里开始,main activity可能会启动其他activity,为诸如写电子邮件和打开单个电子邮件等任务提供屏幕。

    虽然activity可以在应用程序中形成聚合的用户体验,但每个activity都只是松散地绑定到其他activity;在应用程序中,activity之间的依赖性通常是最小的,实际上,activity通常会启动属于其他应用程序的activity。例如,一个浏览器应用程序可能启动社交媒体应用程序的共享activity。

    要在应用程序中使用activity,必须在应用程序的manifest中注册信息,并且必须适当地管理activity的生命周期。本文的其余部分将介绍这些主题。

     

    配置manifest


     声明activities

    要声明您的activity,请打开您的manifest文件,并添加一个 <activity> 元素作为 <application> 元素的子元素。例如: 

    <manifest ... >
      <application ... >
          <activity android:name=".ExampleActivity" />
          ...
      </application ... >
      ...
    </manifest >

      这个元素唯一需要的属性是android:name,它指定activity的类名。您还可以添加定义activity特性的属性,如标签、图标或UI主题。

        发布应用程序后,不应该更改activity名称。如果这样做,可能会破坏一些功能,比如应用程序快捷键

    声明intent filters

    intent filters是Android平台的一个非常强大的特性。它们提供了基于明确的请求和隐式请求启动activity的能力。例如,一个明确的请求可能会告诉系统“在Gmail应用程序中启动发送邮件activity”。相比之下,当系统UI询问用户在执行任务时使用哪个应用程序时,隐式请求告诉系统“在任何可以完成任务的activity中启动发送电子邮件屏幕”。这就是intent filters在起作用。

    通过在 <activity>元素中声明 <intent-filter>属性,您可以利用这个特性。该元素的定义包括<action>元素和,可选地一个<category> 元素和/或 <data> 元素。这些元素结合在一起,指定您的activity可以响应的intent类型。例如,下面的代码片段展示了如何配置发送文本数据的activity,并接收来自其他activity的请求:

    <activity android:name=".ExampleActivity" android:icon="@drawable/app_icon">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>
    </activity>

    在本例中, <action> 元素指定该activity发送数据。声明 <category>元素为 DEFAULT,使activity能够接收启动请求。<data>元素指定此activity可以发送的数据类型。下面的代码片段展示了如何调用上面描述的activity:

    // Create the text message with a string
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");
    sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
    // Start the activity
    startActivity(sendIntent);

     如果你想让你的应用程序是独立的,不允许其他应用程序激活它的activity,你不需要任何其他 intent filters。您不希望向其他应用程序提供的activity应该没有intent filters,您可以使用明确的 intents来启动它们。

    声明permissions(权限)

    您可以使用manifest的 <activity>标记来控制哪些应用程序可以启动特定的activity。除非两个activity在其manifest中具有相同的权限,否则父activity不能启动子activity。如果您为特定的activity声明一个 <uses-permission> 元素,那么调用activity必须有一个匹配的 <uses-permission> 元素。

    例如,如果你的应用程序想要使用一个名为SocialApp的虚拟应用程序在社交媒体上分享一个帖子,SocialApp本身必须定义一个该应用程序必须拥有的权限:

    <manifest>
    <activity android:name="...."
       android:permission=”com.google.socialapp.permission.SHARE_POST”
    
    />

     然后,要被允许调用SocialApp,你的应用程序必须匹配SocialApp的清单上的权限集:

    <manifest>
       <uses-permission android:name="com.google.socialapp.permission.SHARE_POST" />
    </manifest>

     

    管理activity生命周期


     在activity声明周期中,一个activity要经过若干状态。您使用一系列回调来处理状态间的转换。下面的部分将介绍这些回调。

    onCreate()

    您必须实现这个回调,该回调在系统创建activity时触发。您的实现应该初始化activity的基本组件:例如,应用程序应该创建视图并将数据绑定到这里的列表。最重要的是,在这里必须调用setContentView()来定义activity的用户界面的布局。

    当onCreate()完成时,下一个回调总是onStart()。

     onStart()

    当onCreate()退出时,activity进入Started状态,activity对用户可见。这个回调包含了activity用于进入前台并进行交互的最后准备工作。

    onResume()

    系统在activity开始与用户交互之前调用这个回调。此时,activity位于activity堆栈的顶部,并捕获所有用户输入。大多数应用程序的核心功能都是在onResume()方法中实现的。

     onPause()回调始终跟随着onResume()。

    onPause()

     当activity失去焦点并进入Paused 状态时,系统调用onPause()。例如,当用户点击Back或Recents按钮时,就会出现这种状态。当系统为您的activity调用onPause()时,技术上意味着您的activity仍然部分可见,但大多数情况下是指用户将离开activity,activity将很快进入Stopped状态或Resumed状态。

     如果用户期望UI更新, Paused 状态中的activity可能会继续更新UI。此类activity的示例包括显示导航地图屏幕或播放媒体播放器。即使这样的activity失去了焦点,用户也希望他们的UI能够继续更新。

     您不应该使用onPause()来保存应用程序或用户数据、进行网络调用或执行数据库事务。

     onPause()完成执行后,下一个回调要么是onStop(),要么是onResume(),这取决于activity进入暂停状态后发生的情况。

     onStop()

    当activity不再对用户可见时,系统调用onStop()。这可能会发生,因为activity正在被销毁,一个新的activity正在启动,或者一个现有的activity正在进入一个 Resumed 状态,并且正在覆盖停止的activity。在所有这些情况下,停止的activity都不再可见。

    如果该activity返回与用户交互,系统调用的下一个回调是onRestart(),或者如果该activity完全终止,则是onDestroy(),

     onRestart()

    当 Stopped 状态的activity即将重新启动时,系统调用此回调。onRestart()从停止activity的时候恢复activity状态。

     这个回调总是紧接着onStart()。

    onDestroy()

    系统在activity被销毁之前调用这个回调。

     这个回调是activity接收到的最后一个回调。onDestroy()通常用以确保当activity或包含该activity的进程被销毁时,所有activity的资源都被释放。

     

    转载于:https://www.cnblogs.com/tysdeblog/p/8567132.html

    展开全文
  • But this should not take away from the fact that regardless of who is competing for resources, the system <em>wants</em> to route activities at 2200 routed activities per second to keep up with the ...
  • Introduction to Activities 与mian()启动应用程序不同,android有自己的特殊方式和生命周期启动。 The concept of activities 移动应用不同于桌面应用,简言之,用户交互各种各样。 Declare intent filters...

    Introduction to Activities

    与mian()启动应用程序不同,android有自己的特殊方式和生命周期启动。
    

    The concept of activities

    移动应用不同于桌面应用,简言之,用户交互各种各样。
    

    Declare intent filters

    如果你不想别的应用程序启动此Activity 你就不声明Intent filters,本应用使用显示跳转
    

    Declare permissions

    对应Activity申请使用权限,
    
    <manifest>
    <activity android:name="...."
       android:permission=”com.google.socialapp.permission.SHARE_POST”
    
    />
    
    <manifest>
       <uses-permission android:name="com.google.socialapp.permission.SHARE_POST" />
    </manifest>

    Managing the activity lifecycle

    onCreate():页面初始化和数据绑定,切必须调用setContentView()。方法结束后接下来调用onStart。
    onStart():onCreate完成之后,页面可见,做好准备到达前台参与用户体验。
    onResume():活动开始与用户交互之前调用回调,次Activity位于栈顶,捕获用户所有输入,核心功能在此完成。
    onPause():当活动失去焦点并进入暂停状态时调用。即使失去焦点,处于暂停状态下也可以更新UI,地图导航和媒体播放。(不应再在这里面做用户数据保存,网络请求,数据库数据存储)。
    onStop():页面不可见,可能是页面被破坏,现有活动正在进入恢复状态并且正在覆盖已停止的活动。
    onRestart():当处于“已停止”状态的活动即将重新启动时,系统将调用此回调
    onDestroy():销毁活动之前调用,此回调是活动收到的最后一个回调。通常实现onDestroy()以确保在活动或包含它的进程被销毁时释放所有活动的资源。
    如图:
    

    这里写图片描述

    展开全文
  • custom activities

    2019-09-22 04:58:02
    Useful Sharepoint Designer Custom Workflow Activities http://spdactivities.codeplex.com/ http://stackoverflow.com/questions/1783746/how-to-disable-the-editing-of-the-item-after-it-was-...
    Useful Sharepoint Designer Custom Workflow Activities

     

    http://spdactivities.codeplex.com/

     

     

    http://stackoverflow.com/questions/1783746/how-to-disable-the-editing-of-the-item-after-it-was-approved-in-sharepoint-wss

     

    转载于:https://www.cnblogs.com/zyip/p/3255032.html

    展开全文
  • <div><p>In order to matain compatibility with the code generated by the designer we should move the Microsoft.CSharp.Activities to te System.Activities project. <p>This avoid us to change the generate...
  • District wise activities

    2020-12-26 01:08:44
    <div><p>Added district wise activities. Needed for: https://github.com/covid19india/covid19india-react/issues/292 Sample response: ...
  • Cannot Select Activities

    2020-12-09 10:14:29
    dropdown menu neither lets me type an activity nor does it show any activities. As a result, I cannot stop the timer. <p>Despite this, I can select the "Active Trackers" tab and delete the ...
  • Remove custom activities

    2021-01-08 04:51:22
    - The following custom activities should be gone: - GooglePlus - Instapaper - Pocket <p>However if you have any of those applications installed in your device you should be to use their standard share...
  • Activities not syncing

    2020-11-24 15:00:13
    <ol><li>Fresh installation of the Elevate app plugin</li><li>Started sync</li><li>Sync founds 249 activities and processed them all</li><li>No activities are shown.</li><li>selected option "...
  • Activities not Syncing

    2020-11-21 23:23:55
    Doing a Sync or Full Sync is not fetching recent activities. <strong>Actual Behavior:</strong> After a manual sync or full sync, 5 recent cycling activities are not included on the multisports ...
  • Clean up activities

    2020-11-24 16:47:33
    ve run into using test-butler with Espresso testing, is that activities don't get cleaned up. I've had to adopt code ...
  • <div><p>When displaying the activities activity I now get a weird gray strip up top with an info icon that doesnt seem to do much. What gives? <p><img alt="device-2018-07-13-102854" src=...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 12,502
精华内容 5,000
关键字:

activities