-1

I am trying to take text that was generated in one activity, that was concatenated, "MainActivity.java," and display it on screen using another activity, "DICS.java." I am having trouble figuring out how to do that.

MainActivity.java

package com.example.tristan.a1p1n1;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;


public class MainActivity extends AppCompatActivity {


    public final static String EXTRA_MESSAGE = "com.example.tristan.a1p1n1.MESSAGE";
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    public void sendMessage(View view)
    {
        Intent intent = new Intent(this, DICS.class);
        EditText editText = (EditText) findViewById(R.id.editText);
        EditText editText2 = (EditText) findViewById(R.id.editText2);
        String message = editText.getText().toString() + editText2.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);

    }}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.tristan.a1p1n1.MainActivity">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="Enter a String"
        android:ems="10"
        android:layout_below="@+id/textView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/editText" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="Enter a String"
        android:ems="10"
        android:id="@+id/editText2"
        android:layout_below="@+id/editText"
        android:layout_alignRight="@+id/editText"
        android:layout_alignEnd="@+id/editText"
        android:layout_marginRight="11dp"
        android:layout_marginEnd="11dp"
        android:layout_marginTop="13dp" />

    <Button
        android:text="+"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="23dp"
        android:id="@+id/button"
        android:onClick="sendMessage" />
</RelativeLayout>

DICS.java

package com.example.tristan.a1p1n1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;


/**
 * Created by Tristan on 2/11/2017.
 */
public class DICS extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dics);

    }
}

dics.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TextView
        android:text="@+id/sendMessage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView2" />
</LinearLayout>
Tristan
  • 85
  • 9

2 Answers2

2

Intent intent = getIntent(); String dataGet= intent.getExtras().getString("EXTRA_MESSAGE");

MateenSheikh
  • 142
  • 1
  • 10
0

Get the intent and then proceed to get the string from the intent

Intent intent = getIntent();
String stringFromIntent = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
Br0thazS0ul
  • 1,195
  • 2
  • 11
  • 20