I have two activities: MainActivity and SecondActicity. On MainActivity I click on a button and go to SecondActicity:
public void GoToSeconActivity(View view) {
Intent intent = new Intent(this, secondActivity.class);;
startActivity(intent);
}
On secondActivity I click on a button and then I go back to MainActivity and also send extras:
public void goBackToMainActivity() {
Intent intent = new Intent(getBaseContext(), MainActivity.class);
intent.putExtra("myVar", myVar);
startActivity(intent);
}
on MainActivity's onCreate I want to show myVar in an EditText
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
Bundle extras = getIntent().getExtras();
if (extras != null)
{
View myView = getLayoutInflater().inflate(R.layout.fragment_main, null);
EditText myVarEdittext1 = (EditText)myView.findViewById(R.id.myVarEditText);
string str = extras.getString("myVar");
myVarEdittext1.setText(str, TextView.BufferType.EDITABLE);
}
}
But it doesn't work.
I try to add myVarEdittext1.postInvalidate();
after setText and it didn't help.
I also tried to put this code in
mHandler.post(new Runnable() {
@Override
public void run() {
View myView = ....
//...
myVarEdittext1.setText(str, TextView.BufferType.EDITABLE);
}
});
and it didn't help too...
What else can I do? There is no exception - but the editText remains empty.