1

I am developing a very basic widget for Android. My widget has a variable that keeps the users choices, it's declared as static. The problem is that after a while, I suspect after a long stand by, the widget get's somewhat emptied out and the static variable becomes empty. What is the the solution to save the state of my widget without losing the "history" of it's life? onSaveInstanceState onPause are not defined for AppWidgetProvider. Any suggestion?

4

1 に答える 1

0

で保存できますSharePreference。使用するたびに、まず変数が空 (null) でないかどうかを確認し、そうである場合は、保存されているバージョンを に取得してみてくださいSharedPreferences。また、変数が更新されるたびに、それを SharedPrefs に保存します。

if(variable==null){
   variable = getFromSharedPrefs();
}

// Use it further
于 2012-08-13T07:54:27.567 に答える