onStop / onPause / onDestroy with Threads

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

Sponsored Links

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

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

public someMethods()

final Handler h = ....;

Thread thread1 = new Thread()
        public void run()
                // use Handler h to notify when complete


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. Querying AlarmManager to determine if alarms are set

Hi there, does anyone know if its possible to query the AlarmManager
to see if/what alarms are set?

I can set an alarm using:

AlarmManager am =
Intent i = new Intent(getApplicationContext(), OnAlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(getApplicationContext(),
0, i,
        SystemClock.elapsedRealtime(), Const.UPDATE_INTERVAL_MS, pi);

And i can then cancel it using:


But i can not figure out how to determine if the alarm is still set
(e.g. so an activity can inform the user that the scheduled task is
already set).  AlarmManager has not "isSet()" method.

Can anyone shed any light on this?  Is it even possible?

many thanks in advance.

2. onConfigurationChanged-function


i have a question:
If I want to handle the configuration changes in my own way, which
things must I consider??
In the AndroidManifest.xml, I can set:
- mcc, mnc, locale, touchscreen, keyboard, keyboardHidden, navigation,
orientation, screenLayout, fontScale

Are there more possible configChanges or "only" this ten??? What
happened, if someone call me. I think there will be no recreation of
the activity after finish the call?

And if I use the onConfigurationChanged-function - must I really setup
the view a second time like in onCreate()?? And must I save the
states of the variables and so on?? I don't think so!?


3. End call event

4. .GIF Support

5. does linear interpolator work?

6. OpenGL and transparent PNG's

7. Input Method Manager