views:

26

answers:

3

I have two different activities in my project.I intend to pass data from one activity to another. (As per user interface, I select an item from The spinner in one activity and send it as text msg.) The coding for text msg is done in another activity i.e the second activity.

I m successfully able to select the desired item from the Spinner but am not able to pass it as text message . I have tried using

 Bundle b=new Bundle();
 b.putString("Message",message );
 intent.putExtras(b);
 startActivity(intent);

to select the item from first activity. It functions well BUT HOW DO I CAPTURE/RECEIVE THIS In the second activity that will send it as a text message.

b = getIntent().getExtras();
String s=b.getString("Message");

The above mentioned code does not function and force closes the application.

A: 

Hi

would you please check my blog post on passing data between activities:

http://android-pro.blogspot.com/2010/06/android-intents-part-2-passing-data-and.html

thanks

Mina Samy
A: 

Learn how to use the logcat: http://developer.android.com/guide/developing/tools/adb.html And you would find that you get an ActivityNotFoundException. Which is fixed by adding the second activity to your AndroidManifest.xml.

e.g.

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".ActivityA"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="ActivityB"></activity>

</application>

Where the important part is:

<activity android:name="ActivityB"></activity>
Cpt.Ohlund