Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I defined a listener for my receiver and use it in activity and it is running perfect now. Is it possible to happen any problem later?</p> <pre><code>public interface OnNewLocationListener { public abstract void onNewLocationReceived(Location location); </code></pre> <p>}</p> <p>in My receiver class wich is named as ReceiverPositioningAlarm:</p> <pre><code>// listener ---------------------------------------------------- static ArrayList&lt;OnNewLocationListener&gt; arrOnNewLocationListener = new ArrayList&lt;OnNewLocationListener&gt;(); // Allows the user to set an Listener and react to the event public static void setOnNewLocationListener( OnNewLocationListener listener) { arrOnNewLocationListener.add(listener); } public static void clearOnNewLocationListener( OnNewLocationListener listener) { arrOnNewLocationListener.remove(listener); } // This function is called after the new point received private static void OnNewLocationReceived(Location location) { // Check if the Listener was set, otherwise we'll get an Exception when // we try to call it if (arrOnNewLocationListener != null) { // Only trigger the event, when we have any listener for (int i = arrOnNewLocationListener.size() - 1; i &gt;= 0; i--) { arrOnNewLocationListener.get(i).onNewLocationReceived( location); } } } </code></pre> <p>and in one of my activity's methods:</p> <pre><code>OnNewLocationListener onNewLocationListener = new OnNewLocationListener() { @Override public void onNewLocationReceived(Location location) { // do something // then stop listening ReceiverPositioningAlarm.clearOnNewLocationListener(this); } }; // start listening for new location ReceiverPositioningAlarm.setOnNewLocationListener( onNewLocationListener); </code></pre>
 

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