이렇게 새 설치와 업데이트가 달라질 수 있습니다.
String StoredVersionname = "";
String VersionName;
AlertDialog LoginDialog;
AlertDialog UpdateDialog;
AlertDialog FirstRunDialog;
SharedPreferences prefs;
public static String getVersionName(Context context, Class cls) {
try {
ComponentName comp = new ComponentName(context, cls);
PackageInfo pinfo = context.getPackageManager().getPackageInfo(
comp.getPackageName(), 0);
return "Version: " + pinfo.versionName;
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
return null;
}
}
public void CheckFirstRun() {
VersionName = MyActivity.getVersionName(this, MyActivity.class);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
StoredVersionname = (prefs.getString("versionname", null));
if (StoredVersionname == null || StoredVersionname.length() == 0){
FirstRunDialog = new FirstRunDialog(this);
FirstRunDialog.show();
}else if (StoredVersionname != VersionName) {
UpdateDialog = new UpdateDialog(this);
UpdateDialog.show();
}
prefs.edit().putString("versionname", VersionName).commit();
}
SharedPreferences는 첫 번째 실행인지 여부를 알려주는 'bFirstRun' 부울을 저장할 수 있습니다. –
하지만 마지막으로 저장된 sharedprefences는 updation.Means에 남아 있습니다. 어떻게 업데이트를 업데이트 할 수 있습니까? – User42590
무슨 뜻인지 잘 모르겠지만'bFirstRun'이라는 SharedPreference가 없다면 처음 실행했을 것입니다. 그런 다음 false로 설정하고 변경을 커밋합니다. 다음 번에 거기에, 틀렸어. 그래서 고토'alwaysRunActivity' –