About calling finish() in activity

Now, my new activity layout file is constructed with using “include” for a sections of a screen that I expect to use at least twice.

This is a details activity screen, I expect user to enter couple fields and I save data in content provider. Simple, happens in many apps. But it’s a first one for me.

Problem: Save button is pressed, I call save() and I call finish(), expecting activity to be switched to a previous one. Data apparently is saved correctly but no, instead of exiting this activity some other stuff is happening. What??

Let’s read about it.

1. Lean every day. : ) Any statement written after finish() will get executed. Interesting,  but I don’t have any other statements after finish (just break, return etc).

2. OnDestroy() is a last call that activity will see before being destroyed.  I guess it’s a good place to put code for back button pressed if you don’t feel like writing onBackPressed() .

3. android:noHistory = “true”. Can play with that.

"Ruby Hilton, Lynn Gardens, Kingsport, Te...

“Ruby Hilton, Lynn Gardens, Kingsport, Tennessee. Another view of the super-finish operation calling for the spraying… – NARA – 532749 (Photo credit: Wikipedia)

I see, any code that comes after finish() is executed.

Oh, that’s right! found additional code.  Finish() is not necessarily the end, more “activity” happens after the finish. Makes a joke.

Take care!

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s