Evorlor
Evorlor

Reputation: 7553

Hello World Android Tutorial

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);
    }

}

Upvotes: 1

Views: 1145

Answers (1)

A--C
A--C

Reputation: 36449

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

Upvotes: 3

Related Questions