1
更新后第一次打开应用程序时,最合乎逻辑的启动活动的方式是什么?我知道共享首选是最简单的方法,但共享首选项在应用程序更新中保持不变,所以看起来这种选择不会起作用。有任何想法吗?如何在更新后第一次打开应用程序时仅启动一次活动?
更新后第一次打开应用程序时,最合乎逻辑的启动活动的方式是什么?我知道共享首选是最简单的方法,但共享首选项在应用程序更新中保持不变,所以看起来这种选择不会起作用。有任何想法吗?如何在更新后第一次打开应用程序时仅启动一次活动?
使共享的pref商店的应用程序的版本号:如果版本不同,更新它,然后启动您的活动。
编辑:这是我在做什么新的检查。它加载应用程序信息,获取版本号,如果它已更改,则弹出打开“活动”。
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;
}
太棒了,我感谢你的时间。 – EGHDK
你可以更清楚你的问题吗?到目前为止,您似乎只想允许应用程序的一个实例,这可以通过AndroidManifest.xml完成。 但是我相当肯定我完全不理解这个问题。 – Shark