zoukankan      html  css  js  c++  java
  • SharedPreferences存取应用程序访问时间

    package com.example.sharepre1;
    
    import java.util.Date;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.SharedPreferences;
    import android.content.SharedPreferences.Editor;
    import android.view.Menu;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
        private TextView showtime;
        private static final String FILENAME = "time";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            showtime = (TextView) findViewById(R.id.showtime);
            SharedPreferences preferences = getSharedPreferences(FILENAME,0);
            String lasttime = preferences.getString("time", null);
            
            if(lasttime==null){
                lasttime = "第一次使用本应用程序";
            }else{
                lasttime = "你上次访问的时间为"+lasttime;
            }
            Editor editor = preferences.edit();
            editor.putString("time", new Date().toLocaleString());
            editor.commit();
            showtime.setText(lasttime);
        }
    
    }
  • 相关阅读:
    PGA
    impdp导入job
    11g SQL Monitor
    Oracle buffer cache
    OGG异常处理
    Android中dp、dpi与px的关系
    android:gravity设置居中的问题
    Oracle触发器详解
    Android selector中的item的顺序
    selector在color和drawable目录下的区别
  • 原文地址:https://www.cnblogs.com/84126858jmz/p/4910488.html
Copyright © 2011-2022 走看看