15 comments

hey
can you tell me how i can pass that data to fragment ?
i mean i want broadcasted data in fragment for example – i have A activity which hold 2 fragments fragment B > c. so how can i pass data to fragment c ?

Thank you for this… i am trying trying to create an app.. where my broadcast receiver should monitor the network status when the user is on call…and it should notify an error if the network goes out when the user is on the middle of the call… can i follow the same approach???

I got the general idea about Broadcast Receivers from this tutorial. But suppose i want to catch power button click from broadcast receiver, how can i do it? can you please show me an example? (I am a newbie in android programming. Any help would be appreciated).

@Darko Goles, thanks for the quick reply. Your tutorial is very well explained.

I was wondering how can you notify an Activity when it is onPause and has previously launched an IntentService waiting for it to finish.

Let’s suppose you update the UI according to a network response made by an IntentService. The Activity launches the IntentService, activity goes to background (onPause is called), IntentService finishes and wants to notify UI. If broadcast receiver is not attached, the activity will not receive the response. For this scenario I have been looking around for a robust solution and came up with these possibilities:
– Handle Activity-IntentService communication with StickBroadcast in order for the activity to get the last broadcast sent by the IntentService when it comes to foreground (very hacky solution I think)
-Handle Activity-Service communication binding the Activity to the Service and querying the Service to know if it has finished operation (binding makes source code grow up a lot i think and seems way to much effort)
– Handle Activity-IntentService communication and operation on a worker Fragment (setting fragment to setRetainInstance(true). I think this approach is the convenient one but comes with too much effort also.

According to your experience, which of these possibilities is the correct one? If none, which one do you prefer to use? Thanks.

How can the activity receive the broadcast if it is onPause()? If the service has dispatch a notification that it has stopped working and the Activity is onPause(), how does the activity knows the service status if it has unregistered the receiver? thanks!

Your email address will not be published. Required fields are marked *

Comment *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.