package lc.sqlitedata.save.orio;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.widget.Toast;
public class UseCount extends Activity {
SharedPreferences preferences;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sql_sharedpreference);
preferences = getSharedPreferences("count", MODE_WORLD_READABLE);
editor=preferences.edit();
int count=preferences.getInt("count",0);
Toast.makeText(UseCount.this, count+"次", 5000).show();
editor.putInt("count", ++count);
editor.commit();
}
}【特別詳解】Toast.makeText(context, text, duration)text,必須有漢字,如上文Toast.makeText(UseCount.this, "程序以前被使用了"+count+"次", 5000).show();表示了程序被使用的次數如果寫成Toast.makeText(UseCount.this, count, 5000).show();程序報錯,望大家謹記
android數據庫存儲方法(一)---------------SharedPreferences(實例)記錄應用程序使用次數(一)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Android數據庫GreenDao,封裝實踐
黑蛋丶
2020-07-06 02:32:16
SQlite數據庫簡介&介紹以及使用API調用
sky不羁的人生
2020-06-04 13:57:05
Android數據庫:Litepal getDatabase called recursively
哑巴湖小水怪
2020-06-03 06:39:20
Android數據庫:Litepal性能分析及使用中遇到的坑
哑巴湖小水怪
2020-06-03 06:39:20
數據庫LitePal使用教程
大话亭
2020-06-02 22:13:39
Android數據庫框架 greenDAO:3.2.0的集成
zhang106209
2020-06-01 20:54:20
Android SQLite數據庫的建立和增刪改查
万事胜意L
2020-04-25 07:21:09
android數據庫
lzjqcc
2020-02-21 02:15:12
Android開發---DBFlow數據庫使用
Mr丶吴
2019-10-26 05:47:48
android數據庫加密 miniorm-sqlcipher
meng020712
2019-10-26 05:16:17
Android數據庫加密
总有刁民想杀寡人
2019-09-15 17:04:49
android sqlite數據庫升級
总有刁民想杀寡人
2019-09-15 17:04:39
Android SQLDatabase類中的insert方法nullColumnHack字段的含義
Luckie stone
2019-08-06 02:09:31
Android數據庫:Litepal-異步操作-1.5新特性
黄阿火
2019-07-30 01:43:34
三分鐘搞定Android數據庫升級
王爷也疯狂
2019-03-13 15:42:39
最新文章