Tôi đang sử dụng các tùy chọn được chia sẻ để lưu trữ số lần ứng dụng của tôi đã được khởi chạy. Chỉ vào lần khởi chạy đầu tiên, tôi hiển thị thông báo Chào mừng cho người dùng biết về các tính năng mới và thay đổi trong phiên bản đó.SharedPreferences behavior on Update/Uninstall
Nhưng khi tôi hấp thụ khi cài đặt lại ứng dụng hoặc nâng cấp ứng dụng, tôi không thể xóa các tùy chọn được chia sẻ trước đó. tôi muốn nhận được hộp thoại khi tôi cài đặt lại phần mềm hoặc nâng cấp nó.
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();
}
}
thế nào đã lần đầu tiên bạn đã tạo sharedPreference .. – ngesh