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. How to reflect the settings changed in the web to the device

Hello all,
In my Gps app there is a Setting page.
user can make changes to the setting page
 from device and from web , like others(register , login etc).
so when the user make some changes in the settings page form the web
how could it get reflected in the device setting page.

i am not finding a flexible solution.

if anybody have knowledge please help me.

Thanking in advance,

Best Regards
Subrat Kumar Panda
India

-- 

2. How to get information about my application from market

The sites you're seeing this on (like cyrket.com, androlib.com et al)
have broken the market API, which requires some clever work on their
part. It's not terribly difficult but you risk getting cut off by
Google. Hopefully, Google will open up the market API to our use soon,
I think we're seeing some of this happening with their feedback
experiment. One thing you can count on with Google, they will make
data and API's available eventually if there is any good use a
developer can put it to.

-John Coryat

-- 

3. How to get information about my application from market

4. android:orientation="horizontal"

5. How to fix the image size(28 x 29 png file) in the grouptIndicator of the ExpandableListview ???

6. Open Browser with full screen

7. Not calling OnStop when an incoming call is received