1

I am running the Hello World app successfully through an emulator (with Eclipse). I have followed every step from the android website. The app runs and gives me the option to enter a String and click Send. Unfortunately, when I click send, nothing happens. I have completed this app through the tutorial, and I have tried setting the message to something within the code, but no success. It is my best guess that DisplayMessageActivity.java is not running, because I have tried giving the message to be displayed a preset String, but have not been successful. I know this is a fairly vague question, but I cannot seem to find the next step to solve this problem, hence the question. Thanks! Let me know if you need to see any additional code; here is my code for MainActivity.java:

package com.example.myfirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
 public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// // Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.activity_main, menu);
// return true;
// }
 //** Called when the user clicks the Send button *
 public void sendMessage(View view){
 //Do something in response to the button
 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);
 }
}
neatnick
1,5081 gold badge18 silver badges30 bronze badges
asked Dec 10, 2012 at 1:10

1 Answer 1

3

You need to call startActivity (intent); from your sendMessage(). Put it right before the closing brace.

answered Dec 10, 2012 at 1:11
Sign up to request clarification or add additional context in comments.

2 Comments

Got it. Thanks. It has been accepted!And if you don't mind me asking, what exactly is startActivity(intent); doing? I would like to put a comment above it that I can refer to later as needed.
It starts your new Activity as the name states. Meaning that when that piece of code is executed it will send you to the class pointed by the Intent!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.