Android 即时运行-热交换、热交换和冷交换之间的差异

Android 即时运行-热交换、热交换和冷交换之间的差异,android,android-studio,android-instant-run,Android,Android Studio,Android Instant Run,我已经更新到了android studio的最新版本(2.1)。文档中提到,android studio最新版本将在android studio的即时运行功能中支持热-热交换和冷交换 有人能告诉我热-热交换和冷交换的区别吗?此功能被称为Insant Run 中的表中列出了其工作方式和工作时间的详细说明。请阅读以获取详细信息。主要详情如下: 什么是热插拔、热插拔和冷插拔? 热插拔 这是最快的交换类型,几乎可以看到更改 马上。您的应用程序保持运行,并且存根方法 下次调用该方法时将使用新的实现 热交换

我已经更新到了android studio的最新版本(2.1)。文档中提到,android studio最新版本将在android studio的即时运行功能中支持热-热交换和冷交换


有人能告诉我热-热交换和冷交换的区别吗?

此功能被称为Insant Run

中的表中列出了其工作方式和工作时间的详细说明。

请阅读以获取详细信息。主要详情如下:

什么是热插拔、热插拔和冷插拔? 热插拔

这是最快的交换类型,几乎可以看到更改 马上。您的应用程序保持运行,并且存根方法 下次调用该方法时将使用新的实现

热交换

此交换仍然非常快,但需要自动活动 当Instant Run将更改的资源推送到目标时重新启动 装置。你的应用程序一直在运行,但屏幕上可能会出现一点闪烁 当活动重新启动时显示屏幕,这是正常的

冷交换

(API级别21或更高):即时运行推送结构代码 更改目标设备并重新启动整个应用程序

对于运行API级别20或更低的目标设备,Android Studio 部署APK的完整构建


触发这些交换的代码更改类型 什么触发了热插拔?

Change implementation code of an existing instance method or static method
Change or remove an existing resource
Structural code changes, such as:

 - Add, remove, or change:
 - an annotation
 - an instance field
 - a static field
 - a static method signature
 - an instance method signature

Change which parent class the current class inherits from

Change the list of implemented interfaces

Change a class static initializer

Reorder layout elements that utilize dynamic resource IDs
什么触发了热交换?

Change implementation code of an existing instance method or static method
Change or remove an existing resource
Structural code changes, such as:

 - Add, remove, or change:
 - an annotation
 - an instance field
 - a static field
 - a static method signature
 - an instance method signature

Change which parent class the current class inherits from

Change the list of implemented interfaces

Change a class static initializer

Reorder layout elements that utilize dynamic resource IDs
什么触发了冷交换?

Change implementation code of an existing instance method or static method
Change or remove an existing resource
Structural code changes, such as:

 - Add, remove, or change:
 - an annotation
 - an instance field
 - a static field
 - a static method signature
 - an instance method signature

Change which parent class the current class inherits from

Change the list of implemented interfaces

Change a class static initializer

Reorder layout elements that utilize dynamic resource IDs
  • 热插拔:–

    当代码位于现有数据库中时,会发生热交换 方法实现已更改。新方法的实现是 下次被应用程序调用时使用。发生热交换 即时,如果已配置,则伴随toast消息 在设备屏幕上,显示“应用的代码更改而不更改” 活动重新启动”

  • 热交换:–

    对的资源文件进行更改时 项目(例如布局更改或字符串修改) 或颜色资源设置)执行即时运行热交换。A. 热交换涉及重新启动当前正在运行的活动。 通常,当活动重新启动时,屏幕将闪烁。温暖的 交换在设备屏幕上通过toast消息报告,该消息如下 “已应用更改,已重新启动活动”

  • 冷交换:–

    结构代码更改,例如添加新的 方法,对现有方法的签名的更改或更改 到项目的类层次结构触发冷交换,其中 整个应用程序将重新启动。请注意,冷交换不会导致 正在设备上重新安装的应用程序。


    • 我找到了这个完美的帖子。它用图形说明了这个概念

      快速回顾是:

      热插拔:-在运行代码中所做的更改。无需重新启动。节省时间

      热交换:-进行更改并重新启动特定活动

      冷交换:-重新启动活动以访问更改

      注意:-根据个人经验,在热插拔中,onCreate()中指定的值在Resume()上[或在onCreate之外]不可用,因此会变为null。因此,如果仅在onCreate()块中初始化值,onResume()可能会引发nullPointerException。

      (我不确定这是否是唯一的情况,如果我的逻辑和推理错误,请评论/编辑。)

      这可能有用:为什么我不能触发
      热插拔
      ?它只在模拟器上发生吗?当它发生时,我需要重新启动活动吗?