Saturday, August 13, 2011

[android-developers] Re: Activity onPause and onResume Question

It might help to read (and memorize) the activity life-cycle (here:
http://developer.android.com/reference/android/app/Activity.html)

A phone rotation destroys the current activity unless you override
onConfigurationChanged. Don't just "override" it though - make sure
you know what to include, what to exclude and when to call the
appropriate "super.xxx" methods.

Also, onResume is called when the activity first loads and after it is
paused or stopped. It sounds like the ambiguity arises from it being
called when you don't expect it, not because it behaves erratically.

Also, read up on the Application class (e.g. public class MyApp
extends Application) - for storage of "global" type variables. There
is a lot to that area of Android. Tread with caution.

-Jim


On Aug 12, 1:32 pm, TheWanz <jameswans...@gmail.com> wrote:
> I would like to know the best practice approach to accomplishing this
> in Android:
>
> Main Activity:  Contains 1 textview, 1 opens menu and 1 global thread-
> based class.  The global thread-based class that opens a socket and
> reads in data via TCP/IP, and sends thread-safe notification to the
> main activity so that it can update its textview.  This class is
> developed and works well when it is called from the main activity's
> onCreate method.
> Preferences Activity:  This activity allows the user to choose options
> for host and TCP/IP.
>
> Here are my questions:
> 1. How do I keep my global class from being destroyed when the onPause
> is called?  Every time I rotate the phone or enter the preferences
> activity, the object is trashed.
> 2. How do I capture the event that the user has entered preferences
> and it is time to start my global class?  I have tried onResume, but
> there is ambiguity between when the app is loaded and when the
> preferences screen was exited.
>
> Thanks in advance...

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment