Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体

10 questions online user: 59


How to send objects through bundle

I need to pass a reference to the class that does the majority of my processing through a bundle.

The problem is it has nothing to do with intents or contexts and has a large amount of non-primitive objects. How do I package the class into a parcelable/serializable and pass it to a startActivityForResult?


You can also make your objects Serializable and use the Bundle's getSerializable and putSerializable methods.

我試過了,很快意識到這是不切實際的。我不認為存儲在傳遞類(線程)中的大多數對像都是可序列化的。:)雖然謝謝。 - ahodder 2010年11月23日18:00


Possible solution:

Bundle bundle = new Bundle();
bundle.putSerializable("key", new CustomObject());

Class CustomObject:

class CustomObject implements Serializable{
 private SubCustomObject1 sc1;
 private SubCustomObject2 sc2;

Subcustom objects:

class SubCustomObject1 implements Serializable{ }

class SubCustomObject2  implements Serializable{ }

I came across this question when I was looking for a way to pass a Date object. In my case, as was suggested among the answers, I used Bundle.putSerializable() but that wouldn't work for a complex thing as the described DataManager in the original post.

My suggestion that will give a very similar result to putting said DataManager in the Application or make it a Singleton is to use Dependency Injection and bind the DataManager to a Singleton scope and inject the DataManager wherever it is needed. Not only do you get the benefit of increased testability but you'll also get cleaner code without all of the boiler plate "passing dependencies around between classes and activities" code. (Robo)Guice is very easy to work with and the new Dagger framework looks promising as well.

好吧,有了類似Date的東西,你可以傳遞長值。但是,其餘的聽起來不錯。謝謝。 - ahodder 2013年2月8日15:46


another simple way to pass object using a bundle:

  • in the class object, create a static list or another data structure with a key
  • when you create the object, put it in the list/data structure with the key (es. the long timestamp when the object is created)
  • create the method static getObject(long key) to get the object from the list
  • in the bundle pass the key, so you can get the object later from another point in the code

Use Bundle-NativeCode on Linux does not work

I create a plugin which includes the following folder structure:

  • src
  • native/so/libsystemcommand.so

The manifest include the command

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Commands Plug-in
Bundle-SymbolicName: de.system.commands;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: de.system.commands.CommandsPlugin
Bundle-Localization: plugin
Bundle-NativeCode: native/so/libsystemcommand.so; osname = Linux; processor = x86
Require-Bundle: org.eclipse.core.runtime,
Eclipse-AutoStart: true
Export-Package: de.system.commands,
Bundle-ClassPath: .

The build.properties looks like

source.. = src/
output.. = bin/
bin.includes = META-INF/,

In the start method of my Activator class I call


At runtime the library is not found and a UnsatisfiedLinkError is thrown.

java.lang.UnsatisfiedLinkError: no libsystemcommand in java.library.path

Do I have to set more attributes in the plugin? Do I have to unzip some informations on the target platform?



I wonder if the library needs to be specified without the lib prefix? E.g.,


Since that is how the library would be passed on a gcc link line.

謝謝,但這也行不通。 - Markus Lausberg 09年1月23日13:53

mindprod.com/jgloss/runerrormessages.html#UNSATISFIEDLINKERROR建議相反(添加.so後綴)是正確的答案。 - 安德魯Eidsness 09年1月23日14:00

你是對的!!!圖書館必須加載開始“lib” - Markus Lausberg 09年1月23日15:09


In a plugin fragment for linux, I use:

Bundle-NativeCode: librptlc.so; osname = linux; processor=x86

And in the main plugin I use:

if (OS.equals(Platform.OS_LINUX)) {

This should work within one plugin too.

I seem to remember having some problems with libraries in a sub folder in the jar, but I'm not sure why this would be the case. I just stuck to having the libraries in the root of a plugin fragment instead, which works for me.

You could also try getting the file system path of the library (not sure if that's easy) and loading it using:

libraryPath = "C:eclipseundles123librptlc.so";

I think i found the solution.

We only build the plugin which was not working and copy it to the destination platform directory. After this we start the application as wtach the log files whether the library was foud or not.

What we miss, was to delete the configurations folder. The new plugin was not unzipp and the library was not existing in the configurations directory.

Im sorry and thank you for your answers.


The configuration folder is placed at


At least delete everything without the file


容易犯錯誤,很難看出後果。同樣的事發生在我身上.... - MarioOrtegón09年2月2日在13:04

@Markus Lausberg - 我想我遇到了同樣的問題,但我不明白你的意思是“刪除配置文件夾”。它在哪里以及如何刪除它? - MrMas 2013年4月4日22:58

我增強了我的答案並將配置文件夾路徑打印到 - Markus Lausberg 2013年4月5日7:25


The lib has to be in your filesystem (not in an archive file). Then you can either use the linux environment variable LD_LIBRARY_PATH pointing to the lib or define the property java.library.path

我希望,插件可以做到這一點,因為在Windows平台上,這是沒有額外的庫路徑。 - Markus Lausberg 09年1月23日13:36

@flolo - 你錯了; Eclipse框架支持從插件包(JAR文件)加載本機庫。 - 麥克道爾09年1月23日14:11


OSX: Environment variables pointing to application bundles?

I want cscope to open files in MacVim instead of vim, so I'm trying to have the path to MacVim as the Value of the EDITOR environment variable which is used by cscope:

$ export EDITOR=/Applications/MacVim.app/Contents/MacOS/MacVim

If I'm now trying to edit a file from within ctags, it won't work and throws this error message:

$ MacVim[8384:10b] No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting

Calling MacVim from the commandline with

$ /Applications/MacVim.app/Contents/MacOS/MacVim

works, though.

How can I fix this?

up vote 10 down vote accepted favorite

Make sure you put the mvim script in your path, and try this out:

export EDITOR="mvim -f"

This was the ticket for me when using MacVim as editing git commit messages.

注意-f,它是--no-fork標誌。這是關鍵。 - 吉姆加文2009年2月13日16:42

謝謝你的回答,我使用了EDITOR =“vim”作為git,但是它一直在破碎。這個“mvim -f”完美無缺! - 湯姆洛克霍斯特於2009年5月10日14:57


Have you tried export EDITOR=/Applications/MacVim.app?

Or wrapping MacVim in a small script that uses open to start the app?


It works fine for me when I set my EXPORT variable to exactly that, and start a git commit. What are you using that's calling it? Have you considered setting EXPORT to point to the mvim script that comes on the MacVim disk image instead?



My launch tool is designed for this. It's like Apple's open, but allows you to get the path to an application bundle rather than launching it. For example:

% launch -ni com.apple.safari

launch is in Fink and MacPorts too.



What is a “bundle” in an Android application

What is a bundle in an Android application? When to use it?

up vote 264 down vote accepted favorite

Bundles are generally used for passing data between various Android activities. It depends on you what type of values you want to pass, but bundles can hold all types of values and pass them to the new activity.

You can use it like this:

Intent intent = new...
Intent(getApplicationContext(), SecondActivity.class);
intent.putExtra("myKey", AnyValue);  

You can get the passed values by doing:

Bundle extras = intent.getExtras(); 
String tmp = extras.getString("myKey");

You can find more info at:

為什麼不直接使用System.object和強制轉換? - lovespring 2014年8月24日12:23


Pass data between activities by using Bundle and Intent objects.

Your first create a Bundle object

Bundle b = new Bundle();

Then, associate the string data stored in anystring with bundle key "myname"

b.putString("myname", anystring);

Now, create an Intent object

Intent in = new Intent(getApplicationContext(), secondActivity.class);

Pass bundle object b to the intent


and start second activity


In the second activity, we have to access the data passed from the first activity

Intent in = getIntent();

Now, you need to get the data from the bundle

Bundle b = in.getExtras();

Finally, get the value of the string data associated with key named "myname"

String s = b.getString("myname");

這是非常好的VERBOSE答案,謝謝。 - Abhiode 1月11日13:58


I have to add that bundles are used by activities to pass data to themselves in the future.

When the screen rotates, or when another activity is started, the method protected void onSaveInstanceState(Bundle outState) is invoked, and the activity is destroyed. Later, another instance of the activity is created, and public void onCreate(Bundle savedInstanceState) is called. When the first instance of activity is created, the bundle is null; and if the bundle is not null, the activity continues some business started by its predecessor.

Android automatically saves the text in text fields, but it does not save everything, and subtle bugs sometimes appear.

The most common anti-pattern, though, is assuming that onCreate() does just initialization. It is wrong, because it also must restore the state.

There is an option to disable this "re-create activity on rotation" behavior, but it will not prevent restart-related bugs, it will just make them more difficult to mention.

Note also that the only method whose call is guaranteed when the activity is going to be destroyed is onPause(). (See the activity life cycle graph in the docs.)

如果我們可以使用映射,為什麼要使用bundle?謝謝泰德! - Ruchir Baronia 2016年1月28日1:37

Bundle不僅被Activity使用。Fragment還使用它來保持旋轉後的狀態。 - 王凱2016年8月4日16:49


A Bundle is very much like a Java Map object that maps String keys to values. It's used to pass information between activities and other application components. It's also used by the framework to capture and restore state information.

The reason Android doesn't use plain old Map objects for this is that Map is too flexible; it can contain objects (such as, say, I/O streams) that cannot be serialized. The Bundle API restricts the types of objects that can be added to a bundle in such a way that the bundle's contents are guaranteed to be serializable. The Android framework relies on this property.

I suggest that you read the documentation on Application Fundamentals. This explains, among other things, what bundles and intents are and what they are used for.


Bundles can be used to send arbitrary data from one activity to another by way of Intents. When you broadcast an Intent, interested Activities (and other BroadcastRecievers) will be notified of this. An intent can contain a Bundle so that you can send extra data along with the Intent.

Bundles are key-value mappings, so in a way they are like a Hash, but they are not strictly limited to a single String / Foo object mapping. Note that only certain data types are considered "Parcelable" and they are explicitly spelled out in the Bundle API.

到目前為止,這是唯一真正接近OP問題的答案,即什麼是捆綁。stackoverflow.com/a/6236801/1588163提供了更多見解。 - 2014年10月3日10:55

如果我們可以使用映射,為什麼要使用bundle?謝謝! - Ruchir Baronia 2016年1月28日1:37

@RuchirBaronia沒有特別的理由使用Bundle,除非你打算將它傳遞給需要Bundle對象的Android API的一部分。 - scriptocalypse 2016年1月28日1:46


Just create a bundle,

Bundle simple_bundle=new Bundle();
Intent i=new Intent(getApplicationContext(),this_is_the_next_class.class);

IN the "this_is_the_next_class.class"

You can retrieve the items like this.

Intent receive_i=getIntent();
Bundle my_bundle_received=receive_i.getExtras();

Bundle is used to pass data between Activities. You can create a bundle, pass it to Intent that starts the activity which then can be used from the destination activity.

有了這種方法,有沒有辦法重新獲得CLI應用/控制台界面的功能?我喜歡將模型保留在任何捆綁包之外的位置,但我希望保留對CLI功能的訪問權限。 - 安迪貝爾德於2012年8月24日16:47

這應該被捆綁在一起:) - d0001 12月28日12:03


Bundle:- A mapping from String values to various Parcelable types.

Bundle is generally used for passing data between various activities of android.

when we call onPause() then onStop() and then in reverse order onStop() to onPause().

The saved data that the system uses to restore the previous state is called the "instance state" and is a collection of key-value pairs stored in a Bundle object.

映射,是bundle的本質。 - BollMose 2016年2月1日1:28

你介意給我一個如何做到這一點的例子嗎? - Daniel Ribeiro 12年3月3日19:06

由於標籤symfony-2.0,我假設你使用當前的2.0版本。在這種情況下,您可以隨意創建一個git存儲庫並將所有內容放入其中,您希望獨立於symfony進行開發。在你的symfony項目更新你的deps文件,如這裡提到的symfony.com/doc/current/cookbook/workflow / ...然後只需創建一個(或多個)應用程序包(php app / console generate:bundle)特定於symfony的東西。 - KingCrunch 12年3月3日20:32


bundle is used to share data between activities , and to save state of app in oncreate() method so that app will come to know where it was stopped ... I hope it helps :)


use of bundle send data from one activity to another activity with the help of intent object; Bundle hold the data that can be any type.

Now I tell that how to create bundle passing data between two activity.

Step 1: On First activity

Bundle b=new Bundle();


Intent in=new Intent(getApplicationContext(),secondActivity.class);



Step 2: On Second Activity

Intent in=getIntent();

Bundle b=in.getExtras();

String s=b.getString("mkv");

I think this is useful for you...........

但後來我將應用程序與KnpRadBundle聯繫起來......在這個問題上沒有更簡單的方法嗎? - Daniel Ribeiro於2012年4月3日19:16

依賴於symfony的部分(控制器,模型,模板等)將始終與symfony耦合,因為您正在使用它(擴展類,使用幫助程序等等)。單獨工作的類將位於Company命名空間中,您可以使用依賴項容器加載它們。這些類可以獨立於框架。 - miguel_ibero 12年3月3日19:21

問題是,Bundle的概念直接公開分享。當我編寫一些應用程序時,我不想分享我的代碼,除了那些我故意構建為社區驅動模塊的部分。我錯了嗎? - Daniel Ribeiro於2012年4月3日19:37

您不必共享捆綁包。將捆綁包視為具有一些配置的一組類。在每個項目中,您可以擁有不同的包。 - miguel_ibero 12年3月3日19:45

你應該閱讀symfony書 - miguel_ibero 12年3月3日19:47


Bundle is not only to transfer data between two different components but more importantly it is used to restore the values stored before activity is destroyed into new activity.

such as the text in an EditText widget or the scroll position of a ListView.


First activity:

String food = (String)((Spinner)findViewById(R.id.food)).getSelectedItem();
RadioButton rb = (RadioButton) findViewById(R.id.rb);
Intent i = new Intent(this,secondActivity.class);

Second activity:

String food = getIntent().getExtras().getString("food");
Boolean rb = getIntent().getExtras().getBoolean("rb");

您可能還想了解最小,完整和可驗證的示例。 - Daniel Corzo 2016年12月21日21:13


How to run a ruby script within bundler context?

I have a Ruby script called foo.rb, and I want to run it within the context of the bundler environment. How?

bundle exec foo.rb doesn't work, because exec expects a shell script.


IOS: copy a file in documents folder

In my project I have two file .txt (in Resources folder), how can I copy them inside documents folder?


Compiling and running an OSGI application in Eclipse

The base of our enterprise application is OSGI and we have several Java projects that are logically OSGI bundles. We use Maven to compile the application using the Maven Bundle plugin. But this process is time consuming and makes it impossible to debug the application. We also use the Runner and Pax(:provison) plugins to run the application. If we could rely on the Auto build function of Eclipse and also debug the application it would make our lives so much easier. Is there a way to configure Eclipse to be able to compile (and may be run) an OSGI-based application?


I'm not entirely sure if I understand you, but here goes.

Well, running/debugging OSGi applications in Eclipse is really easy, as long as your bundles reside in PDE aware projects or at least are on your target platform.

Do you have the source of all your bundles? Debugging without source isn't all that useful. If you do, can you just import all the source of your bundles into your Eclipse workspace?

Otherwise you can create a target platform, add all your bundles to that. (as a first attempt, I'd say dump all your bundles in a directory and point the target platform there)

Either way, then you should be able to Run (or debug)-> OSGi framework -> New -> Pick your bundles -> Start

You can both pick bundles from or target platform and from your workspace.

哦,你需要一個帶PDE的Eclipse安裝,忘了提一下。 - Frank Lee 2012年8月29日16:27


For building, you can use Eclipse Plugin Development Environment (PDE). Despite its name, it isn't specific to building Eclipse plugins and can be used for working on pure OSGi bundles. Eclipse plugins are OSGi bundles with some extras.

Cannot help you with the running or debugging part, although I do know that some enterprise-oriented OSGi platforms provide extensions to PDE.


If you're already using the maven bundle plugin, you may find that PDE's manifest-first approach isn't a good fit with your existing code-first build (I assume at the end you want both an IDE build for development and debugging, and a command-line build for continuous integration and automated testing).

You have two choices. As others have suggested, you can use Eclipse's integrated PDE, and use Tycho for your maven build. Tycho uses the same data used by PDE, so you don't have to write things down more than once. Alternatively, you can stick with the maven bundle plugin and use bndtools within Eclipse. Like the bundle plugin, bndtools is code-first, so you won't need to worry about maintaining manifests. However, you may find there isn't quite as big a set of features in bndtools as in PDE, and I'd suggest still checking your manifests by hand to make sure you understand what's being generated. Whether you prefer manifest-first or code-first is a bit of a heated philosophical debate.


Look at bndtools. bndtools is using the same bnd that is underlying the maven bundle plugin. You can even use bndtools together with m2e. bndtools is available from the Eclipse market place.


How do I know what data is given in a Bundle?

I'm having a heck of a time figuring out what data is coming to my methods through Intent/Bundles. I've tried adding break points to inspect the data, but I don't see anything. Perhaps because it's a Parcelable I can't manually read it in Eclipse.

For instance, a onActivityResult(int requestCode, int resultCode, Intent data) for a Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI). How do I know what data is available? Notice, I'm not ask for WHAT data is available but how the heck do I figure it out so I can apply the same idea to any Bundle/Intent from the Android framework? Perhaps it's a simple as looking at the docs, but I don't see a full listing of the data and I can't see it in Eclipse. So I'm at a lost.

up vote 75 down vote accepted favorite

Bundle.keySet() gives you a list of all keys in the bundle. That said, typically you just expect certain keys and query them, but keySet() is used to examine bundles you get from somewhere.

謝謝。我怎麼知道這個問題的期待是什麼?我現在看到它的文檔,是嗎? - user123321 2011年6月25日3:16

捆綁包實際上只是一個容器。這完全取決於打包它的應用程序。如果它是你自己的,那麼很明顯 - 它就是你輸入的內容。如果它是別人的(或來自操作系統),那麼它取決於所說的應用程序輸入的內容。選項1:檢查文檔。選項2:詢問應用程序的開發人員。選項3:使用Bundle.keySet()分析傳入的包。 - EboMike 2011年6月25日4:18

Bundle for ContactsContract.Contacts.CONTENT_URI中的東西的文檔是以startActivityForResult開頭的? - user123321 2011年6月28日4:23

它沒有在文檔中指定,因此:不要依賴它。您可以嘗試變聰明並使用Bundle.keySet在使用Google的聯繫人應用程序後查看Bundle內部的內容。但猜猜是什麼:機會是,HTC的聯繫人應用程序返回一個不同的捆綁。或MotoBlur。在您的特定情況下,您唯一可以依賴的是intent的數據,因此請閱讀此處概述的結果:stackoverflow.com/questions/866769 / ... ..您還需要除ID之外的哪些信息? - EboMike 2011年6月28日4:49

似乎不太可能根據環境返回一組不同的“標準”數據。我不關心任何特定的環境。我想知道誰知道我的任何onCallback(Intent數據)處理程序可以使用哪些數據。循環使用鍵看起來非常通用,我無法相信Google會讓開發人員自己解決問題。 - user123321 2011年6月28日4:57

public static String bundle2string(Bundle bundle) {
    if (bundle == null) {
        return null;
    String string = "Bundle{";
    for (String key : bundle.keySet()) {
        string += " " + key + " => " + bundle.get(key) + ";";
    string += " }Bundle";
    return string;

像你這樣的伙伴是我如此活躍的SO給我們現成咖啡的原因:P謝謝 - khandelwaldeval 2015年1月5日12:19


i getting alll key and value of bundle stored...

for (String key : bundle.keySet()) {
    string += " " + key + " => " + bundle.get(key) + ";";


(key)       :(value)    

The only thing you get out of a Bundle is what you put in. Bundles are ways of passing information between activities. If you're in charge of your entire application, you shouldn't need to look inside the Bundle for your objects, you should just grab them. Think hashmap keys... if you don't know the key, it's not like you can search the hashmap.

To place an item into a Bundle and pass it on to the next activity, you need to put it as an Extra. Take a look here for an example of passing data via extras and bundles between activities.

Copied and pasted below:

From Activity1

Intent intent = new Intent(this,myActivity2.class);
Bundle bundle = new Bundle();
bundle.putString("myValue", myValue);

In Activity2

Bundle bundle = getIntent().getExtras();
act2MyValue= bundle.getString("myValue");

bundle install returns “Could not locate Gemfile”

I'm new to Rails and am currently working through a guide. The guide states:

Use a text editor to update the Gemfile needed by Bundler with the contents of Listing 2.1.

source 'https://rubygems.org'

gem 'rails', '3.2.3'

group :development do
  gem 'sqlite3', '1.3.5'

# Gems used only for assets and not required
# in production environments by default.

group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'

gem 'jquery-rails', '2.0.0'

group :production do
  gem 'pg', '0.12.2'

We then install and include the gems using the bundle install command:

    $ bundle install --without production 

If Bundler complains about no such file to load -- readline (LoadError) try adding gem ’rb-readline’ to your Gemfile.)

I followed the steps even adding on gem 'rb-readline' to the Gemfile, but apparently the file can't be found and when I go to my text editor I do see the Gemfile itself. I noticed that they made me put gem 'rails', 3.2.3 and my version of Rails is 3.2.1 so I tried changing it to 3.2.1 but that didn't work either.

Any thoughts or advice would be much appreciated.


You may also indicate the path to the gemfile in the same command e.g.

BUNDLE_GEMFILE="MyProject/Gemfile.ios" bundle install

I had this problem as well on an OSX machine. I discovered that rails was not installed... which surprised me as I thought OSX always came with Rails. To install rails

  • sudo gem install rails
  • to install jekyll I also needed sudo
  • sudo gem install jekyll bundler
  • cd ~/Sites
  • jekyll new <foldername>
  • cd <foldername> OR cd !$ (that is magic ;)
  • bundle install
  • bundle exec jekyll serve
  • Then in your browser just go to and it really should be running

You should be in the same directory of Gemfile


When I had similar problem gem update --system helped me. Run this before bundle install


Search for the Gemfile file in your project, go to that directory and then run "bundle install". prior to running this command make sure you have installed the gem "sudo gem install bundler"


Think more about what you are installing and navigate Gemfile folder, then try using sudo bundle install

這會產生關於未經檢查的強制轉換的警告。這是安全的嗎? - 2017年10月20日21:16


How to specify different install/uninstall order of .msi packages within a Wix bundle?

This is my first Wix bundle so I might not know obvious stuff but I have the following requirement:

If I have a Wix bundle package which inside has a bootstrapper application and two .msi packages (lets call them A and B). I understand that if I put them in a Chain element, they will be installed in that order, in my case I want A to be installed first, then B. However upon uninstalling, I want B to be uninstalled first, than A. Is that possible?



What you are describing is the default behaviour - if Burn installs A before B, then A will also be uninstalled after B.

The order is defined by the After argument of the MsiPackage element, which identifies the package that this package should be installed after. If it is not present then this defaults to the previous element in the parent Chain, so that the order of installation is simply the order of the child elements in your Chain.

謝謝,這對我來說是個好消息:) - Mihai Cozma 12年1月1日13:28