In my program I have two activity, the first one calls the second using Intent, the second one returns some String variables and returns to the first one also using Intent, the problem is that I have an error when starting the 1st activity because there is a bundle without data; although apparently it has no logic, this is just a piece of code to try to explain my problem. As I can solve this, it would be possible to indicate to the program that when starting for the first time do not call the bunde and after having called the 2nd activity already execute ...?
Here is my 1st activity
public class MainActivity extends AppCompatActivity {
private TextView mDumpTextView;
private ScrollView mScrollView;
private Button mBotonSend;
private EditText mTextoEditor1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
mBotonSend = (Button)findViewById( R.id.bt2_SendButton ) ;
mDumpTextView = (TextView) findViewById(R.id.tv1_ReadValues);
mScrollView = (ScrollView) findViewById(R.id.sc1_Scroller);
mTextoEditor1 = (EditText)findViewById( R.id.et1_WriteValues );
Bundle bundle = getIntent().getExtras();
String textoImportado2=bundle.getString("texto2");
mDumpTextView.setText(textoImportado2);
mBotonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), PreferenceActivity.class);
intent.putExtra("texto1", mTextoEditor1.getText().toString());
mTextoEditor1.setText( "" );
startActivityForResult(intent, 0);
}
});
}
}
And here is my 2nd activity
public class PreferenceActivity extends AppCompatActivity {
private TextView mDumpTextView;
private ScrollView mScrollView;
private EditText mTextoEditor1;
private Button mBotonSend;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main2 );
Bundle bundle = getIntent().getExtras();
String textoImportado1=bundle.getString("texto1");
mTextoEditor1 = (EditText)findViewById( R.id.et1_WriteValues );
mBotonSend = (Button)findViewById( R.id.bt2_SendButton ) ;
mScrollView = (ScrollView) findViewById(R.id.sc1_Scroller);
TextView mDumpTextView = (TextView)findViewById(R.id.tv1_ReadValues);
mDumpTextView.setText(textoImportado1);
mBotonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent2 = new Intent(v.getContext(), MainActivity.class);
intent2.putExtra("texto2", mTextoEditor1.getText().toString());
mTextoEditor1.setText( "" );
startActivityForResult(intent2, 0);
}
});
}
}