更新後にアプリを初めて開いたときに、アクティビティを起動する最も論理的な方法は何でしょうか。これには sharedprefs が最も簡単な方法であることは理解していますが、sharedprefs はアプリケーションの更新後も永続的であるため、そのオプションが機能するとは思えません。何か案は?
1 に答える
6
共有設定ストアをアプリのバージョン番号にします。バージョンが異なる場合は、更新してからアクティビティを起動します。
編集:これは、新着情報チェックで私が行うことです。アプリ情報を読み込み、バージョン番号を取得し、変更されている場合はアクティビティを開きます。
public static boolean show(Context c)
{
ApplicationInfo ai = c.getApplicationInfo();
String basis = ai.loadLabel(c.getPackageManager()).toString();
try {
PackageInfo pi = c.getPackageManager().getPackageInfo(c.getPackageName(), PackageManager.GET_META_
DATA);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
String lastVersion = prefs.getString("lastversion", null);
SharedPreferences.Editor edit = prefs.edit();
if(lastVersion == null){
// save the first installed version so we can check and see when it got installed
edit.putString("firstversion", String.valueOf(pi.versionCode));
edit.commit();
}
if(lastVersion == null || pi.versionCode > Integer.parseInt(lastVersion)){
edit.putString("lastversion", String.valueOf(pi.versionCode));
edit.commit();
// show it
Intent i = new Intent(c, WhatsNew.class);
c.startActivity(i);
return true;
}
} catch (Exception e) {
android.util.Log.v("WhatsNew", "Exception checking for release notes for [" + basis +
"]:" + e.getMessage(), e);
}
return false;
}
于 2012-10-22T15:13:31.507 に答える