The document discusses version management for mobile applications. When an application is updated, changes may need to be made to the database, preferences, or data models. The author proposes using an annotation-based library called Fit that automatically calls version-specific procedures based on the application's current and previous version codes, avoiding the need for multiple "if" statements. This allows defining version-specific behavior through annotated methods in a VersionModule class.
4. You may¡
? Change database scheme
? Write new preferences
? Migrate to new data models
? Trigger data synchronization
? and so on¡
5. It could happen!
int current = // get current version code from PackageManager
int previous = // read previous version from Preference
if (current <= previous) { return; }
if (previous < 1) {} // do when the app is updated from 0
if (previous < 2) {} // do when the app is updated from 0 or 1
if (previous < 3) {} // do when the app is updated from 0 ~ 2
if (previous < 4) {}
if (previous < 5) {}
if (previous < 6) {}
6. It could happen!
int current = // get current version code from PackageManager
int previous = // read previous version from Preference
if (current <= previous) { return; }
if (previous < 1) {} // do when the app is updated from 0
if (previous < 2) {} // do when the app is updated from 0 or 1
if (previous < 3) {} // do when the app is updated from 0 ~ 2
if (previous < 4) {}
if (previous < 5) {}
if (previous < 6) {}
7. Too many ¡°if¡± statement!
int current = // get current version code from PackageManager
int previous = // read previous version from Preference
if (current <= previous) { return; }
if (previous < 1) {} // do when the app is updated from 0
if (previous < 2) {} // do when the app is updated from 0 or 1
if (previous < 3) {} // do when the app is updated from 0 ~ 2
if (previous < 4) {}
if (previous < 5) {}
if (previous < 6) {}
8. Just ?t for you
https://github.com/KeithYokoma/Fit
9. Fit
? Annotation based
? Automatically call your procedure
? Reusable method declaration
? No more dull ¡°if¡± statement
10. Version Module class
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
11. Version Module class
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
12. Version Module class
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
13. Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fit.initialize(this, new MyModule());
Fit.getInstance().execute();
}
}
14. Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fit.initialize(this, new MyModule());
Fit.getInstance().execute();
}
}
15. Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fit.initialize(this, new MyModule());
Fit.getInstance().execute();
}
}
17. Behaviour
Version 1 to 4
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
18. Behaviour
Version 1 to 4
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
19. Behaviour
Version 1 to 4
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
20. Behaviour
Version 1 to 4
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
21. Behaviour
Version 1 to 4
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
22. Behaviour
Version 3 to 4
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
23. Behaviour
Version 3 to 4
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}
24. Behaviour
Version 3 to 4
public class MyModule implements VersionModule {
// foo() is called when the app is updated to
// version code = 1, 2 and 3
@VersionCode({1, 2, 3})
public void foo() {}
// bar() is called when the app is updated to version code = 4
@VersionCode(4)
public void bar() {}
}