Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9305303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:53:54+00:00 2026-06-18T23:53:54+00:00

In below code, intent from the first activity to the second only carries 1

  • 0

In below code, intent from the first activity to the second only carries 1 string and I need it to carry 2. I have tried to use bundle to achieve this but I think my problem is in this line

extras.putString(EXTRA_MESSAGE, message);

The second problem that you might notice is I need to get the text to be colored by using a string entered on the first page, however I need to spend more time researching this and the first problem is more important.

If someone could help me to solve this first problem it would be most appreciated

I have all the relevant code below.

Main Activity

package com.example.myfirstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;



public class MainActivity extends Activity {
    public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    public final static String EXTRA_MESSAGE_COLOR = "com.example.myfirstapp.MESSAGE2";



    @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)   {
    Intent i = new Intent(this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);
    EditText editTextcolor = (EditText) findViewById(R.id.edit_message_color);
    String message = editText.getText().toString();
    String messagecolor = editTextcolor.getText().toString();
    i.putExtra(EXTRA_MESSAGE_COLOR, messagecolor);
    Bundle extras = new Bundle();
    extras.putString(EXTRA_MESSAGE, message);
    startActivity(i);
    // Do something in response to button

}

}

Second Activity

 package com.example.myfirstapp;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import android.widget.TextView;

public class DisplayMessageActivity extends Activity {

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Get the message from the intent

        Bundle bundle = getIntent().getExtras();
        String messagecolor = bundle.getString(MainActivity.EXTRA_MESSAGE_COLOR);
        String message = bundle.getString(MainActivity.EXTRA_MESSAGE);


        // Create the text view
        TextView textView = new TextView(this);
        textView.setTextColor(getResources().getColor(R.color.blue));
        textView.setTextSize(100);
        textView.setText(message);
        textView.setText(messagecolor);


        // Set the text view as the activity layout
        setContentView(textView);

        // Make sure we're running on Honeycomb or higher to use ActionBar API
        if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.HONEYCOMB)   {
        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            // This ID represents the Home or Up button. In the case of this
            // activity, the Up button is shown. Use NavUtils to allow users
            // to navigate up one level in the application structure. For
            // more details, see the Navigation pattern on Android Design:
            //
            // http://developer.android.com/design/patterns/navigation.html#up-vs-back
            //
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}

XML File

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical" >
    <EditText 
            android:id="@+id/edit_message"
            android:layout_weight="0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="95dp"
            android:layout_marginTop="50dp"
            android:textSize="20sp"
            android:hint="@string/edit_message" />

    <EditText 
            android:id="@+id/edit_message_color"
            android:layout_weight="0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="95dp"
            android:layout_marginTop="50dp"
            android:textSize="20sp"
            android:hint="@string/edit_message_color" />

    <Button         
            android:layout_weight="0"
            android:layout_marginLeft="55dp"
            android:layout_marginTop="50dp"
            android:layout_width="250dp"
            android:layout_height="70dp"
            android:text="@string/button_send"
            android:textColor="@color/royal_blue"
            android:textStyle="bold"
            android:textSize="30sp"
            android:background="@color/pale_green"
            android:onClick="sendMessage"  />     

 </LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:53:55+00:00Added an answer on June 18, 2026 at 11:53 pm

    Just put that extras Bundle in intent extra and then in next activity you will get the correct response

        Bundle extras = new Bundle();
        extras.putString(EXTRA_MESSAGE, message);
        extras.putString(EXTRA_MESSAGE_COLOR, messagecolor );
        i.putExtras(extras);
        startActivity(i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to show only the first entry from Arraylist . My code below
I am using below code from one of my activity to start another Intent
I want to send data through URL.I've tried the below code: Intent browserIntent =
Hi i have used SurfaceView and taking picture by below code First i am
I have an activity that pulls a String Array from xml and displays a
I have two activities. While switching to second activity by intent, it takes 3-4
I am using the below code to send the mail Intent i = new
below code is my databasehandler class i got it from a tutorial. Beside that
I'm new to Android. I need to start a new intent activity based on
I have an Activity where the user can share an image from the raw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.