Android: different launch actions depending on user preferences

My application starts from the welcome screen, but on this screen it is possible to skip this screen in future launches.

What is the correct way of Android? Initially, I just automatically discovered skipWelcome's preference and switched to 2nd activity with a greeting. But this led to the user clicking the "Back" button on the welcome screen, which we promised never to show again.

Right now, in the greeting activity, I read the preference and call () settings for the current activity:

SharedPreferences preferences = getPreferences(MODE_PRIVATE); boolean skipWelcome = preferences.getBoolean("skipWelcome", false); if (skipWelcome) { this.finish(); } 

And then I implement onDestroy to go to the next operation:

 @Override public void onDestroy() { super.onDestroy(); startActivity(new Intent(Welcome.this, StartFoo.class)); } 

But this leads to some weird visual transitions. I'm starting to think that I need a basic activity that pops up. Welcome only if it is correct and then goes to StartFoo.

+4
source share
2 answers

There are several solutions.

Have you tried just getting started and finishing? I well remember that I work, but I could be wrong.

More precisely, if if (skipWelcome) you can start a new action for the result, then when onActivityResult is called, immediately terminate the greeting activity.

Or you can have your launch activity have no idea (do not install content) and run either a welcome activity or StartFoo.

+2
source

I can not comment on the answer of Mayra or I (not enough rep), but this is the right approach.

Hidden in the Android documentation is this important phrase for Activity.startActivityForResult () ,

"As a special case, if you call startActivityForResult () with requestCode> = 0 during the initial OnCreate (Bundle savedInstanceState) / onResume () of your activity, then your window will not be returned until the result is back from the started activity. This "avoid visible flicker when redirecting to another action."

Another important note is that this call is not blocked and execution continues, so you need to stop onCreate execution by returning

 if (skipWelcome) { // Create intent // Launch intent with startActivityForResult() return; } 

The final part is to immediately end the finale in the onActivityResult welcome activities, as Myra says.

+5
source

All Articles