`
guzizai2007
  • 浏览: 361659 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Activity1.1

 
阅读更多

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map.

 

An application usually consists of multiple activities

 

Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack").

 

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

 

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 you the opportunity to perform specific work that's appropriate to that state change

 

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

 

 

package com.cmge;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

/**
 * @desc	一个简单的Activity
 * @author	ljt
 * @time	2014年8月24日 下午10:42:19
 */
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}

 

 

The two most important callback methods are:

onCreate()

You must implement this method.

The system calls this when creating your activity

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

 

public void setContentView (View view)

Set the activity content to an explicit view. This view is placed directly into the activity's view hierarchy

 

onPause()

The system calls this method as the first indication that the user is leaving your 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).

 

 

Declaring the activity in the manifest

You must declare your activity in the manifest file in order for it to be accessible to the system

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.cmge"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.cmge.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 Theandroid:name attribute is the only required attribute—it specifies the class name of the activity

 

Using intent filters

using the <intent-filter> element—in order to declare how other application components may activate it.

 

The <action> element specifies that this is the "main" entry point to the application. 

 

分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    NFC Activity Technical Specification 1.1.pdf

    《NFC Activity Technical Specification 1.1》是NFC Forum发布的一份技术规范文档,主要定义了NFC控制器(NFCC)与设备主机(DH)之间的通信协议——NFC控制器接口(NCI)版本1.1。这份文档的发布日期为2014年3月31...

    Edexcel GCSE 计算机科学课程活动.doc

    - **Activity 1.1**:编写程序打印出“Hello World”。这是编程学习中最基础的示例,旨在帮助学生熟悉编程环境和基本的输出命令。 - **Activity 1.2**:编写程序在屏幕上显示自己的名字。此活动进一步加深了对输出...

    android mars视频代码 Activity Activity_03源码

    www.mars-droid.com/Android开发视频教程 代码 源码 mars老师讲课 android 视频源码 Activity_03 (在此特别感谢mars的无私奉献,此代码为跟随视频边学边做的)

    WSDL-中文规范1.1.pdf

    此文档是提交给万维网联盟 (W3C) 的一份建议,旨在为 W3C XML Activity 中关于 XML 协议的描述提供参考。文档代表了 Ariba、IBM 和 Microsoft 在服务描述方面当前的思考成果,并整合了 NASSL、SCL 和 SDL 等早期提案...

    android-1.1_r1-windows.zip

    《Android 1.1 开发环境构建与应用详解——基于Windows平台》 Android 1.1,作为Android操作系统的一个早期版本,尽管相比当前的版本显得较为陈旧,但其仍具有重要的历史价值和学习意义。对于想要深入了解Android...

    高通LA.1.1基线Android 管理 Activity和组件运行状态 的系统进程AMS

    高通LA.1.1基线Android内核系统开发-管理 Activity和组件运行状态 的系统进程----ActivityManagerServer(AMS)启动流程分析。该版本为Android 10 ,AMS的启动流程与旧版的不同。详细看文档内容。

    Android Crazy Dice1.1

    开发者需要熟悉Android SDK,掌握Activity、Intent、View等基本组件,以及如何使用XML布局文件来构建用户界面。此外,为了实现游戏逻辑,他们可能还运用了随机数生成器(Random类)来模拟掷骰子的结果,确保每次游戏...

    sdk-android-1.1.66

    标题 "sdk-android-1.1.66" 暗示了这是一个针对Android平台的软件开发工具包(SDK)的特定版本,版本号为1.1.66。SDK是开发者用于构建、测试和调试Android应用程序的核心工具集。通常,它包含API库、编译器、调试器...

    Android Activity和Intent机制学习笔记

    **1.1 定义及作用** 在Android开发中,Activity是最基本的应用组件之一,可以将其理解为用户界面的一个屏幕。它提供了用户与应用交互的主要场所。例如,一个应用可能包含多个Activity,每个Activity负责显示不同的...

    Android实现自定义手势和识别手势的功能

    1. 先完成自定义手势的Activity 1.1 因为需要存储手势文件所以需要声明权限: &lt;uses android:name=android.permission.READ_EXTERNAL_STORAGE&gt; //读取SD卡权限 ...

    Android RoboGuice 使用指南 - v1.1

    ### Android RoboGuice 使用指南 - v1.1 #### 概述 RoboGuice 是一款专为 Android 平台设计的轻量级依赖注入框架,它基于 Google Guice 构建,能够极大地简化 Android 应用程序的开发过程。通过使用 RoboGuice,...

    安卓官网文档20210712-V1.1.rar

    2.版本说明:V1.1: 2.构建首个应用里面的 《5.启动另一个 activity _ Android 开发者 _ Android Developers》增添了java版本:《5.java编程-启动另一个 activity _ Android 开发者 _ Android Developers》

    1.1 样式化常见组件

    在Android应用开发中,"1.1 样式化常见组件"是一个重要的主题,它涉及到如何确保你的应用程序在各种Android版本上保持一致的视觉样式和用户体验。这不仅可以提高用户对应用的整体满意度,也有助于开发者更高效地管理...

    voice_activity_detection:基于深度学习和TensorFlow的语音活动检测

    语音活动检测项目 关键字:Python,TensorFlow,深度学习... 1.1基本安装 $ pip3 install -r requirements.txt $ pip3 install -e . 1.2虚拟环境安装 1.3 Docker安装 构建docker镜像: $ sudo make build (这可能

    android Service Activity三种交互方式(付源码)

    1.1 开启Service Service通常通过Intent启动,我们可以使用`startService()`方法。例如: ```java Intent intent = new Intent(this, MyService.class); startService(intent); ``` 1.2 绑定Service 除了启动,...

    【Android】Activity

    1.1. 设计并实现用户接口 衍生自 View 类的视图,控制 Activity 中特定的矩形空间,例如按钮 衍生自 ViewGroup 类的视图,是布局,例如线性布局 利用视图定义布局的最常见方法是借助保存在你的应用资源内的 XML 布局...

    activityMQ

    ActiveMQ是一种开源的消息中间件,实现了Java消息服务(JMS)1.1规范,它是面向消息中间件(Message-Oriented Middleware,MOM)的一种。消息中间件是一种利用高效可靠的消息传递机制进行与平台无关的点对点或发布/...

    sdk-android-1.1.66.zip

    关于对象状态管理,Android开发者通常会使用`onSaveInstanceState()`和`onRestoreInstanceState()`方法来保存和恢复Activity的状态,或者在Fragment中使用`setArguments()`和`getArguments()`来传递数据。...

    AccessibilityService智能安装卸载APP

    例如,对于安装,我们可以使用Intent.ACTION_VIEW启动一个带有APK文件URI的Activity。 ```java Intent installIntent = new Intent(Intent.ACTION_VIEW); installIntent.setDataAndType(Uri.fromFile(new File...

Global site tag (gtag.js) - Google Analytics