0

ユーザーがマーケット(グーグルプレイ)から新しいアップデートをインストールしたときに初めてアプリでコードを実行する方法があるかどうかを知る必要がありますか?

アプリの新しいバージョンをアップロードするたびにコードを1回実行する必要がありますか?

読んでくれてありがとう。

4

1 に答える 1

6

SharedPreferences を使用してアプリの最新バージョンと現在のバージョンを保存し、バージョンが変更されるたびにコードを実行します。何かのようなもの:

    public static final String LAST_VERSION = "LAST_VERSION";
    public static final int VERSION_CODE = 4; // Same as the version code in your manifest.

    SharedPreferences prefs = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();

    mContext = this;

    int last = prefs.getInt(LAST_VERSION, 0);
    if (last < VERSION_CODE) {
        //Your code
        editor.putInt(LAST_VERSION, VERSION_CODE);
        editor.commit();
    }
于 2013-01-27T08:55:20.773 に答える