import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView; public final class MultiRes extends Activity { private int mCurrentPhotoIndex = 0;
private int[] mPhotoIds = new int[] { R.drawable.sample_0,
R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6,
R.drawable.sample_7 }; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); showPhoto(mCurrentPhotoIndex); // Handle clicks on the 'Next' button.
Button nextButton = (Button) findViewById(R.id.next_button);
nextButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mCurrentPhotoIndex = (mCurrentPhotoIndex + 1)
% mPhotoIds.length;
showPhoto(mCurrentPhotoIndex);
}
});
} @Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("photo_index", mCurrentPhotoIndex);
super.onSaveInstanceState(outState);
} @Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
mCurrentPhotoIndex = savedInstanceState.getInt("photo_index");
showPhoto(mCurrentPhotoIndex);
super.onRestoreInstanceState(savedInstanceState);
} private void showPhoto(int photoIndex) {
ImageView imageView = (ImageView) findViewById(R.id.image_view);
imageView.setImageResource(mPhotoIds[photoIndex]); TextView statusText = (TextView) findViewById(R.id.status_text);
statusText.setText(String.format("%d/%d", photoIndex + 1,
mPhotoIds.length));
}
}

Android 简单案例:onSaveInstanceState 和 onRestoreInstanceState的更多相关文章

  1. Android Activity的onSaveInstanceState() 和 onRestoreInstanceState()方法:

    Android Activity的onSaveInstanceState() 和 onRestoreInstanceState()方法: 1. 基本作用: Activity的 onSaveInstan ...

  2. 保存恢复临时信-Android 中使用onSaveInstanceState和onRestoreInstanceState

    在Activity中,有两个方法用于临时保存.恢复状态信息,这两个方法是: public void onSaveInstanceState(Bundle savedInstanceState); pu ...

  3. Android 简单案例:可移动的View

    CrossCompatibility.rar 1. VersionedGestureDetector.java import android.content.Context; import andro ...

  4. Android 简单案例:继承BaseAdapter实现Adapter

    import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import ...

  5. Android 中onSaveInstanceState和onRestoreInstanceState学习

    1. 基本作用: Activity的 onSaveInstanceState() 和 onRestoreInstanceState()并不是生命周期方法,它们不同于 onCreate().onPaus ...

  6. Android onSaveInstanceState和onRestoreInstanceState()

    首先来介绍onSaveInstanceState() 和 onRestoreInstanceState() .关于这两个方法,一些朋友可能在Android开发过程中很少用到,但在有时候掌握其用法会帮我 ...

  7. Android学习基础之onSaveInstanceState和onRestoreInstanceState触发的时机

    先看Application Fundamentals上的一段话:    Android calls onSaveInstanceState() before the activity becomes ...

  8. android json解析及简单例子+Android与服务器端数据交互+Android精彩案例【申明:来源于网络】

    android json解析及简单例子+Android与服务器端数据交互+Android精彩案例[申明:来源于网络] android json解析及简单例子:http://www.open-open. ...

  9. Android Activity生命周期 onSaveInstanceState和onRestoreInstanceState

    当某个activity变得“容易”被系统销毁时,该activity的onSaveInstanceState就会被执行,除非该activity是被用户主动销毁的,例如当用户按BACK键的时候. 注意上面 ...

随机推荐

  1. Nginx实战系列之功能篇----后端节点健康检查(转)

    公司前一段对业务线上的nginx做了整理,重点就是对nginx上负载均衡器的后端节点做健康检查.目前,nginx对后端节点健康检查的方式主要有3种,这里列出:   1.ngx_http_proxy_m ...

  2. linux下设置了SSH免密码登录但还是需要输入密码的解决办法

    今天在设置linux的免密码登录后,仍然需要输入密码,后来找到了原因,是因为用户没有权限修改.ssh目录下的know_hosts文件导致的. 具体情况是这样的: 在/home/username/.ss ...

  3. Android基础工具类重构系列一Toast

    前言: 一直在考虑写一下Android实际项目中的一些总结,翻看CSDN博客,上一篇已经是一年多曾经. 本系列定位Android基础工具类重构.旨在记录实际项目中经经常使用到的一些工具类,比方Toas ...

  4. ASP.NET C# 获取当前日期 时间 年 月 日 时 分 秒

    我们可以通过使用DataTime这个类来获取当前的时间.通过调用类中的各种方法我们可以获取不同的时间:如:日期(2008-09-04).时间(12:12:12).日期+时间(2008-09-04 12 ...

  5. jQuery方法笔记

    .clone() $(selector).clone(includeEvents) $(this).clone(true) //boolean值,true/false分别对饮是否复制元素的所有事件处理

  6. 奇怪的bug:javascript不执行

    背景:有人想要个简单的js效果,点击某个菜单,其他菜单收起. 说了下思路,结果~~ 只好直接写了一个,代码如下: <!DOCTYPE html> <html> <head ...

  7. 修改MySQL的默认密码的四种小方法

    投稿:lijiao 字体:[增加 减小] 类型:转载 时间:2015-09-05我要评论 对于windows平台来说安装完MySQL后,系统就已经默认生成了许可表和账户,下文中就教给大家如何修改MyS ...

  8. opencv实例一:显示一张图片

    第一个简单的实例,显示一张图片: 1)代码如下 /*************************************************************************** ...

  9. 那些有关求解next数组的算法

    next数组的历史 有关字符串的模式匹配算法中,比较容易写出的是朴素的匹配算法也就是一种暴力求解方式,但是由于其时间复杂度为子串长度和主串长度的乘积,例如strlen(subStr) = n,strl ...

  10. 【Java NIO的深入研究6】JAVA NIO之Scatter/Gather

    Java NIO开始支持scatter/gather,scatter/gather用于描述从Channel(译者注:Channel在中文经常翻译为通道)中读取或者写入到Channel的操作. 分散(s ...