handling broadcast reciver

Posted by rayman on Stack Overflow See other posts from Stack Overflow or by rayman
Published on 2010-05-24T10:38:03Z Indexed on 2010/05/24 10:41 UTC
Read the original article Hit count: 222

Filed under:
|

Hi, I have an app which has MainActivity(without gui.. please just flow with it:) )

now this MainActivity running a service, this service using sendBroadcast() in order to comunnicate with the MainActivity.. now ofcourse i need to registerReceiver in the onResume() of the MainActivity.

but i also need to add unregisterReceiver(receiver) in the onDestroy() of the MainActivity.

problem is: when i first start that app i need it to up the service, and i dont want the user to lose focus, so i press finish() after i`am starting the service.. but then auto invoked also unregisterReceiver(receiver).. and this is not good for me.. i get error it's said it couldnt find any registerd reciver.

so i fixed it by delete this line.. but i am sure its going to 'revenege' me in the future, when/where could i have problem if i wont use unregisterReceiver(receiver).. at the onDestroy()

thanks,

ray.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-sdk