I recently downloaded the Android Development Tool Kit and began doing the "build your first app" tutorial and ran into a problem today, so wanted to post it to this Android discussion forum, to see if anyone could help.


- - - Updated - - -


I recently downloaded the Android Development Took Kit and I'm doing the "build your first app tutorial" found here:

I created and Android Project with Eclipse and ran it successfully by using an Android Virtual Device. I built the simple UI by creating a Linear Layout in the activity_main.xml file. I added a text field, string resource, and a Send Message button. I ran the app at this point, and it displayed this button in the app with a text field for a message to be entered, but at this point there was no way to respond to this message.

The next lesson is where my question comes in, where we added:
to the Button element in the activity_main.xml file.

In the MainActivity.java file, we added the sendMessage method:

/** Called when the user clicks the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);

In this lesson they said:

An Intent is an object that provides runtime binding between separate components (such as two activities). The Intent represents an app’s "intent to do something." You can use intents for a wide variety of tasks, but most often they’re used to start another activity.

Inside the sendMessage() method, create an Intent to start an activity called DisplayMessageActivity (above).

The DisplayMessageActivity class created using the Eclipse IDE:

public class DisplayMessageActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {

// Make sure we're running on Honeycomb or higher to use ActionBar APIs
// Show the Up button in the action bar.

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
return true;
return super.onOptionsItemSelected(item);

In the AndroidManifest.xml file, this Activity was added:

<application ... >
android:name="com.example.myfirstapp.DisplayMessag eActivity"
androidarentActivityName="com.example.myfirstapp.MainActi vity" >
android:value="com.example.myfirstapp.MainActivity " />

with this resource in the strings.xml file:

<string name="title_activity_display_message">My Message</string>

Next step:

Every Activity is invoked by an Intent, regardless of how the user navigated there. You can get the Intent that started your activity by calling getIntent() and retrieve the data contained within it.

In the DisplayMessageActivity class’s onCreate() method, get the intent and extract the message delivered by MainActivity:

To show the message on the screen, create a TextView widget and set the text using setText(). Then add the TextView as the root view of the activity’s layout by passing it to setContentView().

public void onCreate(Bundle savedInstanceState) {

// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

// Create the text view
TextView textView = new TextView(this);

// Set the text view as the activity layout

What was supposed to happen:
When running the app, it opens, type a message in the text field, click Send, and the message appears on the second activity.

What happened when I ran my app:
The button did not show up as it had before I added this part - no button, no text field, etc, so I was unable to type any message in the text field, send the message, and have it appear on the second activity.

There were no errors but there were 3 warnings when I ran my app:
--not targeting the latest versions of Android: compatibility modes apply. Consider testing and updating this version. Consult the android.os.Build.VERSION_CODES javadoc for details. RESOURCE: AndroidManifest.xml

--The import android.annotation.TargetApi is never used.

--The import android.view.Menu is never used

I noticed the DisplayMessageActivity looks at the Android version (Honeycomb or higher) - is there someplace else where I should be looking at the version? Why did it not cause the button and text field to not be there earlier in the app lessons here? They were there before, but disappeared when I added the above responses to entering text and sending it to another activity. Then the button and text field disappeared all together from the app when it was run.

The other warnings are just about not using resources, so did not think those could cause this issue.