꿈소년의 개발 이야기

Activity unregister / Leaked IntentReceiver issue 본문

Android Development

Activity unregister / Leaked IntentReceiver issue

꿈소년 2013. 5. 9. 23:36
반응형

refer to 

http://stackoverflow.com/questions/3577566/android-leaked-intentreceiver-exception-is-being-thrown-even-though-i-call-unre


This is a Android activity life cycle issue. I am seeing it in a main activity and then testing on device with the back button that goes back to a splash screen.

In the onPause() method.

Unregister the Broadcast Receiver that you created in the onCreate()

In the onRestart() re-register a brand new Broadcast Receiver.

In the activity class you need to keep a record of the Broadcast Receiver as instance data member.

SECOND

I think this also a feature enhancement issue with Android.

Sometimes developer need a broadcast receiver to outlive the activity. For example to understand when certain screen states are available or not. Think about a conversation context of work flow model, which has many states.

THIRD

You can register and unregister broadcast receivers with an activity, but a simple call like isRegistered(BroadcastReceiver) in the Activity class might be very useful.

If you need receivers to live beyond the activity, then I do not the answer, except to silence the warning, by adding unregister(X) in the onDestroy() call. YMMV ;-)

'Android Development' 카테고리의 다른 글

SQLiteOpenHelper Singleton instance creating.  (0) 2013.07.04
ndk-stack 으로 so 파일 debugging 하기  (0) 2013.05.13
NFC Guide  (0) 2013.05.08
리눅스 커널과 안드로이드의 Suspend/Resume  (0) 2013.03.30
DDMS thread dump  (0) 2013.03.30