onStop / onPause / onDestroy with Threads

by Ives » Fri, 18 Sep 2009 08:47:28 GMT


Sponsored Links
 Hi,

i uses the combination of Handler and Threads to fetch images for my
app.

I wanted to know if I had create a inline thread:

class
{
public someMethods()
{

final Handler h = ....;

Thread thread1 = new Thread()
{
        @Override
        public void run()
        {
                // use Handler h to notify when complete
        }
};
thread1.start();

}
}

what happens if each of these method was called by the system:
onPause, onStop, onDestroy

Am I correct to assume for onDestroy, a RuntimeException will be
thrown as the object Handler h and whatever the Handler tries to
access has already been cleared by the system.

--~--~---------~--~----~------------~-------~--~----~



onStop / onPause / onDestroy with Threads

by Mark Murphy » Fri, 18 Sep 2009 17:35:29 GMT


 


Generally speaking, that is not correct. The Handler and its underlying
Activity are not "cleared by the system", because you still hold
references to them. The Activity will not be on the screen, and so
whatever you do will not be visible. And, it is conceivable that you
will do something that will cause a disconnected Activity to fail with
an Exception, but you should not be relying upon that behavior.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to *Advanced* Android Development_
Version 1.1 Available!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Browser porting on Android

Hi all,

I am newbie to Android.
  I would like to know if is it possible to port firefox browser on
Android and is it possible to integrate gecko on android? Also please
suggest which open source browser can I port.
Please help me..


Regards,
Chitra

--~--~---------~--~----~------------~-------~--~----~

2. OnSizeChanged and redrawing widget contents

I need to wait until onSizeChanged event raises to populate a
TableLayout as I need to know the real size of that widget, but when I
do that the widget shows empty.

If I do the same in the onCreate event, I get the widget well shown.

What method should I need to call in order to get the widget
refreshed?

Thanks in advance

--~--~---------~--~----~------------~-------~--~----~

3. when program has edittext and webview

4. Update TextView when receiving Network messages

5. Where is zeroconf? (Bonjour?)

6. Compile error?

7. Porting Web Browser on Android