main.xml布局代码分析
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
android:id="@+id/txt"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text=""
/>
android:id="@+id/secondBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second"
/>
second.xml布局文件代码分析
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="SecondActivity"
/>
main.xml所对应的操作代码MainActivity.java
package com.szy.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity
{
private final static String TAG="MainActivity";
private static final String CONTENT = "content";
private Button secondBtn=null;
private EditText txt = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txt=(EditText)findViewById(R.id.txt);
//还原保存的数据
if (null!=savedInstanceState&&savedInstanceState.containsKey(CONTENT))
{
txt.setText(savedInstanceState.getString(CONTENT));
}
secondBtn=(Button)findViewById(R.id.secondBtn);
secondBtn.setOnClickListener(listener);
Log.i(TAG, "MainActivity-->onCreate");
}
@Override
protected void onDestroy()
{
super.onDestroy();
Log.i(TAG, "MainActivity-->onDestroy");
}
@Override
protected void onPause()
{
super.onPause();
Log.i(TAG, "MainActivity-->onPause");
}
@Override
protected void onRestart()
{
super.onRestart();
Log.i(TAG, "MainActivity-->onRestart");
}
@Override
protected void onResume()
{
super.onResume();
Log.i(TAG, "MainActivity-->onResume");
}
@Override
protected void onStart()
{
super.onStart();
Log.i(TAG, "MainActivity-->onStart");
}
@Override
protected void onStop()
{
super.onStop();
Log.i(TAG, "MainActivity-->onStop");
}
//保存状态及数据到content
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
Log.i(TAG, "MainActivity-->onSaveInstanceState");
String content=txt.getText().toString();
outState.putString(CONTENT, content);
}
private OnClickListener listener=new OnClickListener()
{
public void onClick(View v)
{
Button btn=(Button)v;
Intent intent=new Intent();
switch (btn.getId())
{
case R.id.secondBtn:
intent.setClass(MainActivity.this, SecondActivity.class);
break;
}
startActivity(intent);
}
};
}
second.xml布局文件所对应的操作SecondActivity.java
package com.szy.activity;
import android.app.Activity;
import android.os.Bundle;
public class SecondActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}
@Override
protected void onDestroy()
{
super.onDestroy();
}
@Override
protected void onPause()
{
super.onPause();
}
@Override
protected void onRestart()
{
super.onRestart();
}
@Override
protected void onResume()
{
super.onResume();
}
@Override
protected void onStart()
{
super.onStart();
}
@Override
protected void onStop()
{
super.onStop();
}
}
activity布局界面需要在AndroidManifest.xml注册一下
package="com.szy.activity"
android:versionCode="1"
android:versionName="1.0">
android:label="@string/app_name"
android:theme="@android:style/Theme.Wallpaper"
>
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog">
Android Activity中状态保存机制
在Activity中保存用户的当前操作状态,如输入框中的文本,一般情况下载按了home键后,重新进入文本框中的东西会丢下,所以我们要保存当前页面信息,如在写短信的时候接到一个电话,那么当你接电话的时候 ...
android activity状态的保存
今天接到一个电面,途中面试官问到一个问题,如果一个activity在后台的时候,因为内存不足可能被杀死,在这之前如果想保存其中的状态数据,比如说客户填的一些信息之类的,该在哪个方法中进行. onSav ...
【Android4高级编程笔记】深入探讨Android Activity
创建Activity 要创建一个新的Activity,需要对Activity类进行扩展,在新类定义用户界面并实现新的功能. 视图是用来显示数据和提高用户交互的Ui控件.Android提供了多个布局类, ...
android退出登陆后,清空之前所有的activity,进入登陆主界面
如题: android退出登陆后,清空之前所有的activity,进入登陆主界面 在退出登陆时只需要增加一个intent标志 Intent intent_login = new Intent(); i ...
Android基础部分再学习---activity的状态保存
主要是bundle 这个參数 參考地址:http://blog.youkuaiyun.com/lonelyroamer/article/details/18715975 学习Activity的生命周期,我们知 ...
Android Activity的生命周期简单总结
Android Activity的生命周期简单总结 这里的内容参考官方的文档,这篇文章的目的不是去总结Activity是如何启动,如何创造,以及暂停和销毁的,而是从实际开发中分析在Activity各个 ...
Android Activity的生命周期详解
应用程序中,一个Activity通常就是一个单独的屏幕,它上面可以显示一些控件也可以监听并处理用户的事件做出响应. Activity之间通过Intent进行通信.在Intent 的描述结构中,有两个最 ...
Activity具体解释(生命周期、以各种方式启动Activity、状态保存,全然退出等)
一.什么是Activity? 简单的说:Activity就是布满整个窗体或者悬浮于其它窗体上的交互界面.在一个应用程序中通常由多个Activity构成,都会在Manifest.xml中指定一个主的Ac ...
Activity详细解释(生命周期、以各种方式启动Activity、状态保存,等完全退出)
一.什么是Activity? 简单的说:Activity或者悬浮于其它窗体上的交互界面. 在一个应用程序中通常由多个Activity构成.都会在Manifest.xml中指定一个主的Activity, ...
随机推荐
SourceTree安装教程和GitLab配置详解
一.安装Git 链接: http://pan.baidu.com/s/1mh7rICK 密码: 48dj 二.安装SourceTree 链接: http://pan.baidu.com/s/1skWk ...
使用证书部署出现System.Security.Cryptography.CryptographicException 错误解决方案
一.System.Security.Cryptography.CryptographicException: 找不到对象 at System.Security.Cryptography.Cryptog ...
CSS选择器从右向左的匹配规则
CSS选择器从右向左的匹配规则 下面这个栗子,CSS选择器它是如何工作的? .mod-nav h3 span {font-size: 16px;} 如果不知道匹配规则,可能的理解是从左向右匹配:先找到 ...
为什么选择Spring Boot作为微服务的入门级微框架
摘要:1. Spring Boot是什么,解决哪些问题 1) Spring Boot使编码变简单 2) Spring Boot使配置变简单 3) Spring Boot使部署变简单 4) Spring ...
Django 中使用kindeditor
KindEditor 是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即所得编辑效果,开发人员可以用 KindEditor 把传统的多行文本输入框(textarea)替换为可视化的富文本 ...
HTTP和RFC
RFC: Request For Comments(RFC),是一系列以编号排定的文件.文件收集了有关互联网相关信息,以及UNIX和互联网社区的软件文件.目前RFC文件是由Internet Socie ...
Jz2440开发板熟悉
title: Jz2440开发板熟悉 tags: ARM date: 2018-10-14 15:05:56 --- 概述 外部晶振为12M Nand Flash 256M,Nor Flash 2M, ...
[转载] C# 调用C++ DLL 的类型转换
//C#调用C++的DLL搜集整理的所有数据类型转换方式,可能会有重复或者多种方案,自己多测试 //c++:HANDLE(void *) ---- c#:System.IntPtr //c++:Byt ...
[笔记] ubuntu下添加windows的字体
方法如下: 第一步:将windows下喜欢的字体文件copy到一个文件夹中,例如将XP里WINDOWS/FONTS中的字体文件(本人比较贪心,把整个文件夹copy了过来……),在linux中命名为xp ...
Java中的this和super
在Java中有两个非常特殊的变量:this和super,这两个变量在使用前都是不需要声明的.this变量使用在一个成员函数的内部,指向当前对象,当前对象指的是调用当前正在执行方法的那个对象.super ...