0

我正在实现一个具有 MainActivity 、 onlyFirstRunActivity 和 alwaysRunActivity 的应用程序。现在我希望在应用程序安装或更新应用程序时,我的应用程序周期应该是这样的:

MainActivity -> onlyFirstRunActivity -> alwaysRunActivity

安装或更新后,我的应用程序周期应该是:

MainActivity -> alwaysRunActivity

我该如何实施这种情况

4

3 回答 3

1

You can get the update time for your app and save it in a SharedPreference.

Also, you should just make your main activity the always run one.

//In your onCreate for your main activity/.
if(last_update_preference < current_update_time){
   Update last update preference to current update time.
   Run first activity. (Which will finish and bounce you back);
}

To get the current_update_time:

How to get app install time from android

For last update time, see:

http://developer.android.com/guide/topics/data/data-storage.html#pref

于 2013-02-08T16:50:02.860 回答
0

You can try something like this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    App app = (App)getApplication();
    if (app.getApi() != null){
        super.onBackPressed();
        startActivity(new Intent(this, MainActivity.class));
        return;
    }else showLoginForm();//or do something else.
}
于 2013-02-08T16:51:59.500 回答
0

像这样,您可以在新安装和更新之间有所不同。

    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();
            }
于 2013-04-15T16:41:27.083 回答