我有一個小部件,它應該在許多應用程式打開事件后顯示在主螢屏上。我知道我必須使用共享首選項,但我不知道如何實作它。
uj5u.com熱心網友回復:
整數值 = 0; // 當應用程式打開事件呼叫獲取 int 以檢查上次值。
value = prefs.getInt("key") ?? 0 : prefs.getInt("key");
// 當應用程式打開事件呼叫時,將 int 設定為附加值。
SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setInt("key",(value 1));
// 當您想檢查應用程式打開了多少次時,您可以使用它。
SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.getInt("key");
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/337367.html
