Return to the same Activity after finishing
josequintana94 opened this issue · 5 comments
Hi, thank you for this great library. I've been using it and everything is fine and the welcome screen looks perfect, the only thing I don't understand is how to go back to the main layout after showing the welcome screen.
My MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sampleWelcomeScreen = new WelcomeHelper(this, WelcomeActivity.class);
sampleWelcomeScreen.show(savedInstanceState);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
sampleWelcomeScreen.onSaveInstanceState(outState);
}
// If this method should display toast at the end or cancel the welcome screen, it is not doing so
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_WELCOME_SCREEN_RESULT) {
if (resultCode == RESULT_OK) {
Toast.makeText(getApplicationContext(), "Completed (RESULT_OK)", Toast.LENGTH_SHORT).show();
//this Toast is not displayed
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(getApplicationContext(), "Canceled (RESULT_CANCELED)", Toast.LENGTH_SHORT).show();
//this Toast is not displayed
}
}
}
I want you to end or click on "done" to display activity_main again
Hey - thanks, glad it is useful. So what do you see when clicking done? Is the welcome screen closing?
Yes, the welcome screen closes and the app. When I reopen the app everything is OK, the welcome screen no longer appears and activity_main is displayed. Then I want you to click on done and go to activity_main without closing it.
Well, I'll answer my newbie question. I used the onstop method in WelcomeActivity to get back to MainActivity:
public void onStop () {
//do your stuff here
Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
startActivity(intent);
super.onStop();
}
Thanks again 👍
That's strange, the main activity should still be running underneath the welcome screen, and closing the welcome screen should just resume it. Are you calling finish()
or doing anything else that would cause MainActivity
to be closed?
I was having the same problem but fixed it be passing
REQUEST_WELCOME_SCREEN_RESULT
to the
sampleWelcomeScreen.show()
method. Here is the code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sampleWelcomeScreen = new WelcomeHelper(this, WelcomeActivity.class);
sampleWelcomeScreen.show(savedInstanceState,REQUEST_WELCOME_SCREEN_RESULT);
}