Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid BroadcastReceiver or simple callback method?
    primarykey
    data
    text
    <p>In my projects I am using <code>BroadcastReceiver</code>s as a callback from a long running thread (eg. notify the activity that a download was finished and send some response data from a Worker <code>Thread</code> so that the activity can display the appropriate message to the user..). To use <code>BroadcastReceiver</code>s I have to be careful to register and unregister the broadcast receiver each time I am using it and also have to care of what messages to send esspecialy when I am using this method for more different actions(like downloading, making WebService calls etc..). And also to send custom Objects through Broadcast's intent I need also to make the objects <code>Parcelable</code>. </p> <p>Unlike this approach, I have seen also the callback methods approach which appears to be simpler than the method I use. Callback methods are simple Interface methods implementation that can be used to achieve the same effect like the BroadcastRecaiver's in app messaging. This approach doesn't need Parcelable implementation to return complex objects and it doesn't use keys like <code>BroadcastReceiver</code>.. I think the bad part is that I need to check the callback object for null value before I want to call a callback method.. and also to make sure I am running the code from the implementation on the UI thread so I can update the UI without errors. </p> <p>Ok, I hope you understood what I meant to say :). </p> <p>Now the question is do you think that the callback method is better (lighter, cleaner, faster..) than the <code>BroadcastReceiver</code> approach when are used just inside of a single application? (Note that I am not using Android <code>Service</code> for background work.. just <code>AsyncTask</code> and <code>Thread</code>s)</p> <p>Thank you! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload