Home > Software design >  How to trigger fresh install instead of update?
How to trigger fresh install instead of update?

Time:05-21

I'm an android developer and I'll be releasing a new update of my application in the coming days. But the new update is a complete redesign of the app's entire architecture, so I'd like the user to uninstall the previous version of the app before he installs the new version so that all the cached data/already logged in user gets cleared and the user makes a fresh start. I was wondering how I could make this happen? What are my best options? Thanks!

CodePudding user response:

If you use sqflite or shared_preferences simply remove all data in the main() function with clear all keys or clear the database. Then you need to write a function that will execute this part of the code once. So basically that's all.

import 'package:shared_preferences/shared_preferences.dart';

void main(List<String> arguments) async {
  bool isDataCleared = false;
  if (isDataCleared == false) {
    final prefs = await SharedPreferences.getInstance();
    prefs.clear();
    isDataCleared = true;
    prefs.setBool('isDataCleared', isDataCleared);
  } else {
    // Do something or continue
  }
}

I hope it will help!

CodePudding user response:

You must have made the changes in your code previously for it to trigger an update whenever there is a new release automatically. There is a workaround I can think of though:

You can embed some data in this new release which should be passed to the backend. If this new data is not passed, you should log them out with an error message to update the application.

This approach is because the backend is the only common link between the old and new applications.

  • Related