`

Things That Cannot Change

阅读更多
Things That Cannot Change
[This post is by Dianne Hackborn, whose fingerprints can be found all over the Android Application Framework — Tim Bray]


Sometimes a developer will make a change to an application that has surprising results when installed as an update to a previous version — shortcuts break, widgets disappear, or it can’t even be installed at all. There are certain parts of an application that are immutable once you publish it, and you can avoid surprises by understanding them.

Your package name and certificate
The most obvious and visible of these is the “manifest package name,” the unique name you give to your application in its AndroidManifest.xml. The name uses a Java-language-style naming convention, with Internet domain ownership helping to avoid name collisions. For example, since Google owns the domain “google.com”, the manifest package names of all of our applications should start with “com.google.” It’s important for developers to follow this convention in order to avoid conflicts with other developers.

Once you publish your application under its manifest package name, this is the unique identity of the application forever more. Switching to a different name results in an entirely new application, one that can’t be installed as an update to the existing application.

Just as important as the manifest package name is the certificate that application is signed with. The signing certificate represents the author of the application. If you change the certificate an application is signed with, it is now a different application because it comes from a different author. This different application can’t be uploaded to Market as an update to the original application, nor can it be installed onto a device as an update.

The exact behavior the user sees when installing an application that has changed in one of these two ways is different:

If the manifest package name has changed, the new application will be installed alongside the old application, so they both co-exist on the user’s device at the same time.

If the signing certificate changes, trying to install the new application on to the device will fail until the old version is uninstalled.

If you change the signing certificate of your application, you should always change its manifest package name as well to avoid failures when it’s installed. In other words, the application coming from a different author makes it a different application, and its package name should be changed appropriately to reflect that. (Of course it’s fine to use the same package name for the development builds of your app signed with your test keys, because these are not published.)

Your AndroidManifest.xml is a public API
More than just your package name that is immutable. A major function of the AndroidManifest.xml is essentially to declare a public API from your application for use by other applications and the Android system. Every component you declare in the manifest that is not private (that is whose android:exported state is true) should be treated as a public API and never changed in a way that breaks compatibility.

A subtle but important aspect of what constitutes a break in compatibility is the android:name attribute of your activity, service, and receiver components. This can be surprising because we think of android:name as pointing to the private code implementing our application, but it is also (in combination with the manifest package name) the official unique public name for that component, as represented by the ComponentName class.

Changing the component name inside of an application can have negative consequences for your users. Some examples are:

If the name of a main activity of your application is changed, any shortcuts the user made to it will no longer work. A shortcut is an Intent that directly specifies the ComponentName it should run.

If the name of a service implementing a Live Wallpaper changes, then a user who has enabled your Live Wallpaper will have their wallpaper revert to the system default when getting the new version of your app. The same is true for Input Methods, Accessibility Services, Honeycomb’s new advanced Widgets, and so on.

If the name of a receiver implementing a Device Admin changes, then as with the live wallpaper example, the device admin will be disabled when the application is updated. This also applies to other kinds of receivers, such as App Widgets.

These behaviors are an outcome of how the Intent system is used on Android. There are two main kinds of Intents:

Implicit Intents only specify “what” they should match, using actions, categories, data, MIME types, and so on. The exact components that they will find are only determined at run-time, by the Package Manager matching it against the current applications.

Explicit Intents specify a single explicit “who” they should match, through a ComponentName. Regardless of whatever else is in the Intent, it is only associated with the exact manifest package name and class name as given in its ComponentName.

Both of these types of Intents are important to how Android interacts with your application. A typical example of this is how users browse and select live wallpapers.

To let the user pick a live wallpaper, the first thing Android must do is show them a list of the available live wallpaper services. It does this by building an implicit Intent with the appropriate action for a live wallpaper and asking the Package Manager for all services that support this Intent. The result is then the list of live wallpapers shown to the user.

When the user actually selects a specific live wallpaper they want to use, however, Android now must build an explicit Intent that identifies that particular live wallpaper. This is what is handed to the WallpaperManager to tell it which wallpaper to show.

This is why changing the name of the component in your manifest will cause the wallpaper to disappear: the explicit Intent that was previously saved is now invalid because the ComponentName it references no longer exists. There is no information available to indicate what the new name of the component is. (For example consider if your application had two different live wallpaper services the user could select.) Instead, Android must treat that live wallpaper as uninstalled and revert to its default wallpaper.

This is how input methods, device administrators, account managers, app widgets, and even application shortcuts work. The ComponentName is the public unique name of the components you declare in your manifest, and must not change if they are visible to other applications.

In conclusion: There are some parts of your application that can not change. Please be careful.
分享到:
评论

相关推荐

    VclZip pro v3.10.1

    Ofcourse when using regular TStream decendants in D4,4,BCB4,and 5, you cannot create Zip64 archives. If you use Delphi 6, 7, or BCB 6, you don't have to worry about any of this as the normal TSTream ...

    WizFlow网页编辑

    We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license ...

    Universal-USB-Installer

    and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions...

    hibernate-shards.jar

    We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license ...

    ansys技巧全集(很好的ansys技巧 英文版) 很多书上都没有的技巧

    The contents are based on my experience with ANSYS 5.3 -- more recent versions may change things. The contents do not attempt to discuss all the concepts of the finite element method that are ...

    用可控硅控制照明灯的电路原理图

    Things I need to be able to do with new boards. 1. Ability to change wave form shapes. 2. Voltage control (from software control) 3. Pulse Timing control 4. Temp. control (from software control) 5. ...

    selenium-dotnet-2.45.0.zip

    multiple instance automation case, this change means that modifications applied to the anonymous profile can be retained and used in future anonymous profiles. The implication is that the user can ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    If your header file includes other header files, any change to those files will cause any code that includes your header to be recompiled. Therefore, we prefer to minimize includes, particularly ...

    a project model for the FreeBSD Project.7z

    I would like to thank the following people for taking the time to explain things that were unclear to me and for proofreading the document. Andrey A. Chernov Bruce A. Mah Dag-Erling Smørgrav ...

    Turbo C++ 3.0[DISK]

    file of that name cannot be found. If you want to have the command-line compiler assume a .c extension and C language source, use the command-line option -P-c. For more information, see "The ...

    Turbo C++ 3.00[DISK]

    file of that name cannot be found. If you want to have the command-line compiler assume a .c extension and C language source, use the command-line option -P-c. For more information, see "The ...

    C# Game Programming Cookbook for Unity 3D - 2014

    Acknowledgments xiii Introduction xv 1. Making Games the Modular Way 1 1.1 Important Programming Concepts.....................................2 1.1.1 Manager and Controller Scripts.......................

    微软内部资料-SQL性能优化5

    Keeping your clustered key value small increases the number of index rows that can be placed on an index page and decreases the number of levels that must be traversed. This minimizes I/O. As we’ll ...

    外文翻译 stus MVC

    Another noticeable change is that the view uses different technology for implementation than the model or controller. Of course, we could use Java (or PERL, C/C++ or what ever) code to generate ...

    数位板压力测试

    • Is the user allowed to change things that help to customize the work environment, but pre¬vented from changing things over which applications must have control? 2.2 Ease of Programming ...

    微软内部资料-SQL性能优化2

     Identify at least five counters for each subsystem that are key to understanding the performance of that subsystem.  Identify three common myths associated with the memory, I/O, or CPU subsystems...

    Yunus, Muhammad - Creating A World Without Poverty; Social Business and the Future of Capitalism

    Some things to keep in mind as this global integration takes place, is that there should be separate international banks for the global economy; commercial banks for the wealthy and corporations, and...

    convmv-1.15.tar.gz

    If this is not done, JFS does not behave like a POSIX filesystem and it might happen that certain files cannot be created at all, for example filenames in ISO-8859-1 encoding. Only when ...

    正能量英语每日一句PPT课件.pptx

    7. "The things we lose have a way of coming back to us in the end, if not always in the way we expect." 失去的东西可能以不同的方式回归,暗示我们应该接受事物发展的不可预测性,保持开放心态。 8. "You ...

Global site tag (gtag.js) - Google Analytics