我使用共享首選項來存儲我的應用程序啓動的次數。僅在第一次啓動時,我會顯示一條歡迎消息,通知用戶有關該版本中的新功能和更改。更新/卸載時的SharedPreferences行爲
但是,當我專注於重新安裝應用程序或升級應用程序時,我無法刪除先前的共享首選項。當我重新安裝軟件或升級軟件時,我想獲得對話框。
AppLauncher
public class AppLauncher {
static long launch_count = 0;
private static boolean isLaunch = false;
public static void app_launched(Context mContext) {
System.out.println("I m in AppLauncher");
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
if (prefs.getBoolean("dontshowagain", false)) {
return;
}
SharedPreferences.Editor editor = prefs.edit();
// Increment launch counter
launch_count = prefs.getLong("launch_count", 0);
editor.putLong("launch_count", launch_count);
System.out.println("launch_count=" + launch_count);
if (launch_count == 0 || launch_count == 1) {
// showLaunchDialog(mContext);
isLaunch = true;
}
if (isLaunch == true) {
showLaunchDialog(mContext);
isLaunch = false;
}
editor.commit();
}
public static void showLaunchDialog(Context mcontext) {
final Dialog dialog = new Dialog(mcontext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.whatsnew);
Button dismisButton = (Button) dialog.findViewById(R.id.dismisButtom);
System.out.println("inside dialog_started");
dismisButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
dialog.show();
}
}
你怎麼樣首先創建sharedPreference .. – ngesh