I have a simple form in Android, and I want to show a message after clicking the Submit button and after some time it should go to another activity.
My code:
public void submitbuttonHandler(View view) {
boolean isAllFieldsChecked = CheckAllFields();
if (isAllFieldsChecked) {
showMsgSnack("Success");
Intent i = new Intent(AddOsivo.this, MainActivity.class);
startActivity(i);
}
}
public void showMsgSnack(String msg) {
View parentLayout = findViewById(android.R.id.content);
Snackbar snackbar = Snackbar.make(parentLayout, msg, Snackbar.LENGTH_LONG);snackbar.getView().setBackground(ContextCompat.getDrawable(getApplicationContext(),R.drawable.container_snackbar));
snackbar.show();
}
The problem is, it is redirecting immediately and the message can't be seen.
I tried to use Snackbar.LENGTH_LONG
, but it did not help.
I am thinking about using mHandler.postDelayed
but not sure if there is any other solution.
So just to show a message for some seconds and only after that redirect to another activity.