Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling finish() After Starting a New Activity

The first Activity that loads in my application is an initialization activity, and once complete it loads a new Activity. I want to ensure if the user presses 'Back' they go straight to the Launcher, and not the initialization screen. Side note, is this even the best approach, or would this be better done with some kind of Intent Flag?

Is it correct to call finish() after calling startActivity() on the new activity?

onCreate() { ... startActivity(new Intent(this, NextActivity.class)); finish(); ... } 

I'm still taking in the whole 'Message Queue' method of doing things in Android, and my assumption is that calling startActivity() and then finish() from my first Activity's onCreate() will log each respective message in the message queue, but finish execution of onCreate() before moving on to starting the next Activity and finishing my first one. Is this a correct understanding?

like image 960
stormin986 Avatar asked Apr 26 '10 00:04

stormin986


People also ask

How do I finish my current activity and start a new one?

Use finish like this: Intent i = new Intent(Main_Menu. this, NextActivity. class); finish(); //Kill the activity from which you will go to next activity startActivity(i);

What does finish () do in Android Studio?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.

What happens when you call finish () inside onCreate ()?

As per official documentation: You can call finish() from within this function, in which case onDestroy() will be immediately called after onCreate(Bundle) without any of the rest of the activity lifecycle (onStart(), onResume(), onPause(), etc) executing.

How do you end an intent activity?

You need to intent your current context to another activity first with startActivity . After that you can finish your current activity from where you redirect. intent. setFlags(Intent.


1 Answers

Probably you should just use the noHistory flag on the activity in your manifest.xml

like image 88
jqpubliq Avatar answered Oct 23 '22 18:10

jqpubliq