Overriding Activity.finish() does the job;)
Thank you very much, Tseng
@dianne:
ALL samples in the SDK use this mechanism - I already lined out in my
first post, that I didn't like overriding change listeners, since it
is the most useless way I can think about. So, the following should be
done for upcoming releases:
1. Clearly document this behaviour ("When finish() is called you KNOW
you are finishing." Where should I know that from ? Isn't it
imaginable, that the underlying platform has a special way to finish
an activity ?!?)
2. Rather, make an event listener Activity.onFinish() available
3. Remove / adapt SDK examples, which do not comply to platform
standards
All this was just a lack of information not comprehension ;) And thank
you for your efforts ...
On Mar 23, 12:27 am, Tseng <[email protected]> wrote:
> On Mar 5, 11:11 am,Chronos<[email protected]> wrote:> @Tseng: I
> can't find this method - are you talking about class
> > Activity ?
>
> Yes, the final() method is belongs to the activity class and you can
> override it and put your code there.
>
> That's how i did it in my activity class:
>
> @Override
> public void finish() {
> if(bSuccessfullySaved)
> // Notify the caller Activity that the user successfully
> // edited or inserted the data set
> setResult(Activity.RESULT_OK);
> else
> // Notify the caller Activity that the user has canceled the
> activity
> // without altering anything
> setResult(Activity.RESULT_CANCELED);
> super.finish();
>
> }
>
> It was necessary to do it this way. First I tried to do it in the
> button listeners (calling setResult before finish()), but i
> encountered one problem: If a user pressed the "back" button on their
> Android phone, it didn't worked, because he hasn't hit the button. The
> more i was thinking the more i noticed it would become really
> complicated (you'd had to catch all possibilities which could lead to
> a user to exit/finalize the activity and could lead to hardly
> maintainable/readable code (and easily cause errors/bugs when you
> forgot to catch all events)
>
> I then tried to send in onPause or onDestroyed (dunno anymore), but
> this didn't worked to (as Dianne explained it). While testing i
> realized that it could be set before the finish(); call. So i had the
> idea to override the final() method, because finish() is called
> everytime the activity is closed.
>
> This worked very well for me ad at the same time it catched all
> possibile ways on which the application could be closed.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---