请问在的onCreate应用运行在升级? [英] Does onCreate in Application run on upgrading?

查看:232
本文介绍了请问在的onCreate应用运行在升级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的应用程序升级过程中做出一些一次性的器官功能障碍综合征,以我的申请。检查 android.app.Application 的文档,我注意到有的onCreate ,但没有 onUpgrade (如在的 android.database.sqlite.SQLiteOpenHelper )。

我已经把我的升级code。在的onCreate 的方法,但其并不清楚,如果code在升级过程中被执行。

onCreated 称为升级过程中?或者是有运行升级的具体code的另一种方式?

解决方案
  

时onCreated在升级过程中叫什么名字?

没有。 Application.onCreate()当你的应用程序从国家认为开启不跑到跑之称

应用程序考虑运行时,它的包有一个或多个活动进程。它会出现在正在运行的应用程序列表中(不是所有的固件可以向他们展示,但有很多的应用呈现出什么包运行,并有API来获取该列表),并可能有一些正在运行的服务或活动,但不一定!该系统可以让你的应用程序中的运行状态,只要它认为它nesasery,并会杀死它时,它需要重新要求一些内存,如果你明确地把它打死了处理以某种方式(也有API来的,但没有理由通常使用它)。

  

在那里运行升级的具体code的另一种方式?

作为@class堆垛写道: 如果要修改的版本名称或号码,当你实现了新版本 - 你可以检查你的主要活动时,它通过 Activity.onCreate()法版本名称创建,并将其与已保存到共享preference或数据库表中的最后一个版本名称。那么你就可以实现任何逻辑,你想,当你认识到你的版本改变。

您可以检查版本的名称和号码与此code:

  PackageInfo PINFO = this.getPackageManager()getPackageInfo(getPackageName(),0);
     字符串版本code = pinfo.version code;
     字符串VERSIONNAME = pinfo.versionName;
 

希望它帮助你,祝你好运。

I want to make some one-off mods to my application during the app upgrade. Checking the android.app.Application docs, I noticed there is onCreate but no onUpgrade (like in the android.database.sqlite.SQLiteOpenHelper).

I have put my upgrade code in the onCreate method but its not clear if the code is being executed during the upgrade.

Is onCreated called during an upgrade? Or is there another way of running upgrade specific code?

解决方案

Is onCreated called during an upgrade?

no. Application.onCreate() called when your application turning on from state it considers "not running" to "running"

application considered running when it's package have one or more active process. it will appear in the running applications list (not all firmwares can show them, but there's lot's of applications showing what packages running, and there is API to get this list) and probably have some running services or activities, but not necessarily! the system can keep your application in "running" state as long as it thinks it nesasery, and will kill it when it need to re-claim some memory, or if you explicitly killed it process somehow (there is also API to that, but no reason usually to use it).

is there another way of running upgrade specific code?

as @Class Stacker wrote: if you are modifying the version name or number when you realising new version - you can check on your main activity when it creates via the Activity.onCreate() method the version name, and compare it to the last version name you saved to sharedPreference or database table. then you can implement whatever logic you'd like when you recognize your version is changed.

you can check the version name and number with this code:

     PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
     String VersionCode = pinfo.versionCode; 
     String VersionName = pinfo.versionName; 

hope it helped you, and good luck.

这篇关于请问在的onCreate应用运行在升级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆