Passing data/parameter to another Activity

1) make the listview and the two arraylists static

This way you can use the same instances of it from the activity with add button and modify the listview as:

FirstActivity.listDescriptionArraylist.add(listDescriptionString);//this is probably your note

2)if you want to use intents:

while going to the ListActivity pass data by..

intent.putExtra("Title", listTitleString);
intent.putExtra("Content", listDescriptionString);

and to recover it in second activity use:

title= getIntent().getExtras().getString("Title");

Standard way of passing data from one activity to another:

If you want to send large number of data from one activity to another activity then you can put data in a bundle and then pass it using putExtra() method.

             //Create the intent
             Intent i = new Intent(this, ActivityTwo.class);
             String one="xxxxxxxxxxxxxxx";
             String two="xxxxxxxxxxxxxxxxxxxxx";
             //Create the bundle
             Bundle bundle = new Bundle();
             //Add your data to bundle
             bundle.putString(“ONE”, one);
             bundle.putString(“TWO”, two);  
             //Add the bundle to the intent

//Fire that second activity startActivity(i);

ohterwise you can use putExtra() directly with intent to send data and getExtra() to get data.

     Intent i=new Intent(this, ActivityTwo.class);

How do I pass data between Activities/Services within a single application?

Non-Persistent Objects

For sharing complex non-persistent user-defined objects for short duration, the following approaches are recommended:

Singleton class

You can take advantage of the fact that your application components run in the same process through the use of a singleton. This is a class that is designed to have only one instance. It has a static method with a name such as getInstance() that returns the instance; the first time this method is called, it creates the global instance. Because all callers get the same instance, they can use this as a point of interaction. For example activity A may retrieve the instance and call setValue(3); later activity B may retrieve the instance and call getValue() to retrieve the last set value.

A public static field/method

An alternate way to make data accessible across Activities/Services is to use public static fields and/or methods. You can access these static fields from any other class in your application. To share an object, the activity which creates your object sets a static field to point to this object and any other activity that wants to use this object just accesses this static field.

A HashMap of WeakReferences to Objects

You can also use a HashMap of WeakReferences to Objects with Long keys. When an activity wants to pass an object to another activity, it simply puts the object in the map and sends the key (which is a unique Long based on a counter or time stamp) to the recipient activity via intent extras. The recipient activity retrieves the object using this key.

Persistent Objects

Even while an application appears to continue running, the system may choose to kill its process and restart it later. If you have data that you need to persist from one activity invocation to the next, you need to represent that data as state that gets saved by an activity when it is informed that it might go away.

For sharing complex persistent user-defined objects, the following approaches are recommended:

  • Application Preferences
  • Files
  • contentProviders
  • SQLite DB

If the shared data needs to be retained across points where the application process can be killed, then place that data in persistent storage like Application Preferences, SQLite DB, Files or ContentProviders. Please refer to theData Storage for further details on how to use these components.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: