Android基本程序单元Activity

上传人:资****亨 文档编号:488349604 上传时间:2024-05-13 格式:PPTX 页数:17 大小:887.26KB
返回 下载 相关 举报
Android基本程序单元Activity_第1页
第1页 / 共17页
Android基本程序单元Activity_第2页
第2页 / 共17页
Android基本程序单元Activity_第3页
第3页 / 共17页
Android基本程序单元Activity_第4页
第4页 / 共17页
Android基本程序单元Activity_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《Android基本程序单元Activity》由会员分享,可在线阅读,更多相关《Android基本程序单元Activity(17页珍藏版)》请在金锄头文库上搜索。

1、3G3G应用开发之应用开发之AndroidAndroidActivity.学习目标何谓回调Activity简介Activity的生命周期.何谓回调前一节中我们介绍了事件处理机制,这里面就有方法的回调。C,C+或者javascript中经常有回调,但他们是通过指针来实现的,java不能直接操作指针,java中的回调是通过接口来实现的。方法回调是功能定义和功能实现的一种手段,是一种松藕合设计思想。作为一种系统架构,必须有自己的运行环境,并提供用户的实现接口。例如:在activity中定义了很多生命周期中不同状态要调用的方法,这些方法都是空实现,系统框架要调用,用户也要调用来实现。.Activity

2、简介Activity的创立启动另一个ActivityActivity之间传递数据启动另外一个activity并返回结果.Activity的创立Activity提供了和用户交互的可视化界面。创立一个Activity一般是继承Activity(当然也可以继ListActivity,MapActivity),覆盖activity的onCreate()方法,在该方法中调用setContentView()方法展示要显示的视图,调用findViewById()方法实例化组件。注Activity只有在清单文件(全局配置文件)中声明才能使用。.启动另一个Activity像我们在做web开发时,经常会从一个页面

3、跳转到另一个页面,在android中我们也经常会从一个activity中跳转到另一个activity做出一些处理。从一个activity启动另一个activity可以使用startActivity方法或者startActivityForResult方法能够返回结果。这两个方法要传递的参数是android中的另一个非常重要的组件Intent,Intent是相同或者不同组件的信使。.Activity之间传递数据在web开发中我们经常把数据放在某个Scope中如:request,session来实现数据共享。在activity之间传递数据,要使用到对象Bundle,我们将要传递的信息封装到该对象里面

4、,并通过Intent对象传递到另一个Intent中。Activity_03.启动另一个activity并返回结果我们讲述了如何启动另一个activity,有时候我们需要启动另一个activity,并返回一个结果。这里我们就需要使用另一个方法startActivityForResult。1.覆盖onActivityResult方法。从另一个activity中获得返回的结果。2.通过使用startActivityForResult方法传递一个Intent到另一个activity中。3.在另一个activity中通过getIntent方法获得Intent,通过setResult0,intent方法返

5、回结果intent。Chapter05_Activity_StartActivityForResult.Activity LifecycleIf an activity in the foreground of the screen(at the top of the stack),it is active or running.If an activity has lost focus but is still visible(that is,a new non-full-sized or transparent activity has focus on top of your activ

6、ity),it is paused.A paused activity is completely alive(it maintains all state and member information and remains attached to the window manager),but can be killed by the system in extreme low memory situations.Activity LifecycleIf an activity is completely obscured by another activity,it is stopped

7、.It still retains all state and member information,however,it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.If an activity is paused or stopped,the system can drop the activity from memory by either asking it to fin

8、ish,or simply killing its process.When it is displayed again to the user,it must be completely restarted and restored to its previous state.Activity LifecycleThe entire lifetime of an activity happens between the first call to onCreate(Bundle)through to a single final call to onDestroy().An activity

9、 will do all setup of global state in 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 in onDestroy().Activity LifecycleThe visible

10、lifetime of an activity happens between 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.Between these two methods you can maintain resources that are needed to show

11、 the activity 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 an no longer see what you are displaying.The onStart()and onStop()methods can be called multiple times,as the activity becomes

12、visible and hidden to the user.Activity LifecycleThe foreground lifetime of an activity happens between a call to onResume()until a corresponding call to onPause().During this time the activity is in front of all other activities and interacting with the user.An activity can frequently go between th

13、e resumed and paused states-for example when the device goes to sleep,when an activity result is delivered,when a new intent is delivered-so the code in these methods should be fairly lightweight.Activity生命周期主要有4种状态:Active活动Paused暂停Stopped停止Dead死亡.活动、前景状态暂停、背景状态.Activity生命周期其生命周期涉及的函数有:void onCreate(Bundle savedInstanceState)void onStart()void onRestart()void onResume()void onPause()void onStop()void onDestroy()Activity_04,05,06.

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 医学/心理学 > 基础医学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号