相反,动态注册的,我想静态注册我的接收器。 对于动态注册,它工作得很好,我用的是这样的:
..
static private IntentFilter GPSActionFilter;
..
GPSActionFilter = new IntentFilter("GGPS Service");
context.registerReceiver(GPSActionReceiver, GPSActionFilter);
..
static private BroadcastReceiver GPSActionReceiver = new BroadcastReceiver(){
public void onReceive(Context context, Intent intent) { ..}
对于静态注册,调试器从不打的onReceive功能,我使用这样的:
在AndoridManifest:
<receiver android:name="LocationListener$GPSActionReceiver" >
<intent-filter>
<action android:name="LocationListener.ACTION_GPS_SERVICE" />
</intent-filter>
</receiver>
在代码:
public class LocationListener extends BroadcastReceiver
{
public static IntentFilter GPSActionFilter;
public static final String ACTION_GPS_SERVICE = "com.example.LocationListener.GPSActionFilter";
public static BroadcastReceiver GPSActionReceiver;
public void onReceive(final Context context, final Intent intent)
{..}
}