Pass String from one activity to another in android [duplicate]
This question already has an answer here:
Unfortunately MyApp has stopped. How can I solve this?
16 answers
I want to get a string value from one activity to another. When I code and then run it doesn't show any error message in compiler or somewhere, but when priview when I click the button it come back to the HOME SCREEN of the Phone not the app.
These are the codes.
Main Activity
public void submit(View view){
Intent intent = new Intent(this,MessageActivity.class);
TextView textView = findViewById(R.id.input_email);
String display = textView.getText().toString();
intent.putExtra("MESSAGE",display);
startActivity(intent);
}
Message Activity(Second Activity)
public class MessageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
Intent intent = getIntent();
String message = intent.getStringExtra("MESSAGE");
TextView textView = findViewById(R.id.output);
textView.setText(message);
}
public void back(View view){
Intent intent2 = new Intent(this,MainActivity.class);
startActivity(intent2);
}
}
android
marked as duplicate by Mike M.
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 22 at 23:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Unfortunately MyApp has stopped. How can I solve this?
16 answers
I want to get a string value from one activity to another. When I code and then run it doesn't show any error message in compiler or somewhere, but when priview when I click the button it come back to the HOME SCREEN of the Phone not the app.
These are the codes.
Main Activity
public void submit(View view){
Intent intent = new Intent(this,MessageActivity.class);
TextView textView = findViewById(R.id.input_email);
String display = textView.getText().toString();
intent.putExtra("MESSAGE",display);
startActivity(intent);
}
Message Activity(Second Activity)
public class MessageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
Intent intent = getIntent();
String message = intent.getStringExtra("MESSAGE");
TextView textView = findViewById(R.id.output);
textView.setText(message);
}
public void back(View view){
Intent intent2 = new Intent(this,MainActivity.class);
startActivity(intent2);
}
}
android
marked as duplicate by Mike M.
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 22 at 23:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
4
If you mean it's crashing, you'll need to look at the stack trace to determine the cause of the crash.
– Mike M.
Nov 26 '18 at 3:15
It looks like your app just crashes. Please update the question with crash log
– Rainmaker
Nov 26 '18 at 3:25
I too believe it's a crash. There is a tab called Logcat at the bottom of Android Studio. You open it up and check for the error logs.
– parekhkruti26
Nov 26 '18 at 3:30
Just by guessing, it's possibly crashing because the MessageActivity is not registered in the Manifest. Anyways, when you look at LogCat it should tell you why it's crashing.
– lionscribe
Nov 26 '18 at 5:16
Please feel free to respond to comments here, and to edit your question to provide the requested information.
– Mike M.
Nov 27 '18 at 2:23
add a comment |
This question already has an answer here:
Unfortunately MyApp has stopped. How can I solve this?
16 answers
I want to get a string value from one activity to another. When I code and then run it doesn't show any error message in compiler or somewhere, but when priview when I click the button it come back to the HOME SCREEN of the Phone not the app.
These are the codes.
Main Activity
public void submit(View view){
Intent intent = new Intent(this,MessageActivity.class);
TextView textView = findViewById(R.id.input_email);
String display = textView.getText().toString();
intent.putExtra("MESSAGE",display);
startActivity(intent);
}
Message Activity(Second Activity)
public class MessageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
Intent intent = getIntent();
String message = intent.getStringExtra("MESSAGE");
TextView textView = findViewById(R.id.output);
textView.setText(message);
}
public void back(View view){
Intent intent2 = new Intent(this,MainActivity.class);
startActivity(intent2);
}
}
android
This question already has an answer here:
Unfortunately MyApp has stopped. How can I solve this?
16 answers
I want to get a string value from one activity to another. When I code and then run it doesn't show any error message in compiler or somewhere, but when priview when I click the button it come back to the HOME SCREEN of the Phone not the app.
These are the codes.
Main Activity
public void submit(View view){
Intent intent = new Intent(this,MessageActivity.class);
TextView textView = findViewById(R.id.input_email);
String display = textView.getText().toString();
intent.putExtra("MESSAGE",display);
startActivity(intent);
}
Message Activity(Second Activity)
public class MessageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
Intent intent = getIntent();
String message = intent.getStringExtra("MESSAGE");
TextView textView = findViewById(R.id.output);
textView.setText(message);
}
public void back(View view){
Intent intent2 = new Intent(this,MainActivity.class);
startActivity(intent2);
}
}
This question already has an answer here:
Unfortunately MyApp has stopped. How can I solve this?
16 answers
android
android
edited Nov 26 '18 at 4:25
Faysal Ahmed
4,29341434
4,29341434
asked Nov 26 '18 at 3:14
Yasiru RandikaYasiru Randika
1
1
marked as duplicate by Mike M.
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 22 at 23:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Mike M.
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Feb 22 at 23:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
4
If you mean it's crashing, you'll need to look at the stack trace to determine the cause of the crash.
– Mike M.
Nov 26 '18 at 3:15
It looks like your app just crashes. Please update the question with crash log
– Rainmaker
Nov 26 '18 at 3:25
I too believe it's a crash. There is a tab called Logcat at the bottom of Android Studio. You open it up and check for the error logs.
– parekhkruti26
Nov 26 '18 at 3:30
Just by guessing, it's possibly crashing because the MessageActivity is not registered in the Manifest. Anyways, when you look at LogCat it should tell you why it's crashing.
– lionscribe
Nov 26 '18 at 5:16
Please feel free to respond to comments here, and to edit your question to provide the requested information.
– Mike M.
Nov 27 '18 at 2:23
add a comment |
4
If you mean it's crashing, you'll need to look at the stack trace to determine the cause of the crash.
– Mike M.
Nov 26 '18 at 3:15
It looks like your app just crashes. Please update the question with crash log
– Rainmaker
Nov 26 '18 at 3:25
I too believe it's a crash. There is a tab called Logcat at the bottom of Android Studio. You open it up and check for the error logs.
– parekhkruti26
Nov 26 '18 at 3:30
Just by guessing, it's possibly crashing because the MessageActivity is not registered in the Manifest. Anyways, when you look at LogCat it should tell you why it's crashing.
– lionscribe
Nov 26 '18 at 5:16
Please feel free to respond to comments here, and to edit your question to provide the requested information.
– Mike M.
Nov 27 '18 at 2:23
4
4
If you mean it's crashing, you'll need to look at the stack trace to determine the cause of the crash.
– Mike M.
Nov 26 '18 at 3:15
If you mean it's crashing, you'll need to look at the stack trace to determine the cause of the crash.
– Mike M.
Nov 26 '18 at 3:15
It looks like your app just crashes. Please update the question with crash log
– Rainmaker
Nov 26 '18 at 3:25
It looks like your app just crashes. Please update the question with crash log
– Rainmaker
Nov 26 '18 at 3:25
I too believe it's a crash. There is a tab called Logcat at the bottom of Android Studio. You open it up and check for the error logs.
– parekhkruti26
Nov 26 '18 at 3:30
I too believe it's a crash. There is a tab called Logcat at the bottom of Android Studio. You open it up and check for the error logs.
– parekhkruti26
Nov 26 '18 at 3:30
Just by guessing, it's possibly crashing because the MessageActivity is not registered in the Manifest. Anyways, when you look at LogCat it should tell you why it's crashing.
– lionscribe
Nov 26 '18 at 5:16
Just by guessing, it's possibly crashing because the MessageActivity is not registered in the Manifest. Anyways, when you look at LogCat it should tell you why it's crashing.
– lionscribe
Nov 26 '18 at 5:16
Please feel free to respond to comments here, and to edit your question to provide the requested information.
– Mike M.
Nov 27 '18 at 2:23
Please feel free to respond to comments here, and to edit your question to provide the requested information.
– Mike M.
Nov 27 '18 at 2:23
add a comment |
1 Answer
1
active
oldest
votes
Your code works fine for me... Here is my snippets
public void submit(View view) {
TextView textView = findViewById(R.id.editText);
String display = textView.getText().toString();
if (!TextUtils.isEmpty(display)) {
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("MESSAGE", display);
startActivity(intent);
}
}
In the second class:
{
String message = getIntent().getStringExtra("MESSAGE");
System.out.println("message = " + message);
}
Since you are asking that
"when I click the button it come back to the HOME SCREEN of the Phone not the app",
cross check is there any finish() is called in your first activity.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your code works fine for me... Here is my snippets
public void submit(View view) {
TextView textView = findViewById(R.id.editText);
String display = textView.getText().toString();
if (!TextUtils.isEmpty(display)) {
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("MESSAGE", display);
startActivity(intent);
}
}
In the second class:
{
String message = getIntent().getStringExtra("MESSAGE");
System.out.println("message = " + message);
}
Since you are asking that
"when I click the button it come back to the HOME SCREEN of the Phone not the app",
cross check is there any finish() is called in your first activity.
add a comment |
Your code works fine for me... Here is my snippets
public void submit(View view) {
TextView textView = findViewById(R.id.editText);
String display = textView.getText().toString();
if (!TextUtils.isEmpty(display)) {
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("MESSAGE", display);
startActivity(intent);
}
}
In the second class:
{
String message = getIntent().getStringExtra("MESSAGE");
System.out.println("message = " + message);
}
Since you are asking that
"when I click the button it come back to the HOME SCREEN of the Phone not the app",
cross check is there any finish() is called in your first activity.
add a comment |
Your code works fine for me... Here is my snippets
public void submit(View view) {
TextView textView = findViewById(R.id.editText);
String display = textView.getText().toString();
if (!TextUtils.isEmpty(display)) {
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("MESSAGE", display);
startActivity(intent);
}
}
In the second class:
{
String message = getIntent().getStringExtra("MESSAGE");
System.out.println("message = " + message);
}
Since you are asking that
"when I click the button it come back to the HOME SCREEN of the Phone not the app",
cross check is there any finish() is called in your first activity.
Your code works fine for me... Here is my snippets
public void submit(View view) {
TextView textView = findViewById(R.id.editText);
String display = textView.getText().toString();
if (!TextUtils.isEmpty(display)) {
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("MESSAGE", display);
startActivity(intent);
}
}
In the second class:
{
String message = getIntent().getStringExtra("MESSAGE");
System.out.println("message = " + message);
}
Since you are asking that
"when I click the button it come back to the HOME SCREEN of the Phone not the app",
cross check is there any finish() is called in your first activity.
answered Nov 26 '18 at 5:40
Android RajaganapathiAndroid Rajaganapathi
33
33
add a comment |
add a comment |
4
If you mean it's crashing, you'll need to look at the stack trace to determine the cause of the crash.
– Mike M.
Nov 26 '18 at 3:15
It looks like your app just crashes. Please update the question with crash log
– Rainmaker
Nov 26 '18 at 3:25
I too believe it's a crash. There is a tab called Logcat at the bottom of Android Studio. You open it up and check for the error logs.
– parekhkruti26
Nov 26 '18 at 3:30
Just by guessing, it's possibly crashing because the MessageActivity is not registered in the Manifest. Anyways, when you look at LogCat it should tell you why it's crashing.
– lionscribe
Nov 26 '18 at 5:16
Please feel free to respond to comments here, and to edit your question to provide the requested information.
– Mike M.
Nov 27 '18 at 2:23