So i'm trying to launch an Activity when the user is done writing. But instead of launching the Activity, it seems to run the Program again. I'm saying this cause instead of launching the right Activity it launches the first Activity of my program.
search.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if (!event.isShiftPressed()) {
// the user is done typing.
text = search.getText().toString();
new SearchActivity(text);
Intent it = new Intent(MainActivity.this, SearchActivity.class);
startActivity(it);
return true; // consume.
}
}
return false;
}
});
Here is the code for the SearchActivity
public class SearchActivity extends AppCompatActivity {
private String text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
public SearchActivity(String text) {
this.text = text;
}
}
Thank you in advance