Results 1 to 1 of 1
  1. #1
    Member
    Join Date
    Sep 2013
    Location
    Varazze, Italy
    Posts
    1

    Device(s)
    Samsung SII

    Debug broadcast listener

    I implemented a dynamic broadcast listener as an inner class of a main activity but it does not intercept intents. I tried with a static listener with the same intent filter, and it intercepts the same intent. Without going into details, what is the best way to debug listeners? I'm sure that the listener is registered as I put a breakpoint on the registerListener(...) function. If the question is too vague I'll post my code when I'll be in front of my PC.

    This is the code I'm debugging.
    In order to avoid priority issues, I implemented a two step receiver.
    A first static receiver for the connectivity change that fires a new custom defined intent, that should be detected by the networkChangeReceiver.

    package com.storassa.android;

    public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addNetworkChangeReceiver();

    <Other stuff>
    }

    private void addNetworkChangeReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction("com.storassa.android.NETWORK_CHA NGE");

    networkChangeReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

    // check data connection
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();

    // if data connection is now available, get info from Internet
    if (netInfo != null)
    if (netInfo.isConnected()) {

    <Do other stuff>
    }
    }
    };

    registerReceiver(networkChangeReceiver, filter);

    }
    }

    This is the static broadcast receiver (it works).

    public class NetworkReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    context.sendBroadcast(new Intent(
    "com.storassa.android>NETWORK_CHANGE"));

    }
    }
    Last edited by sthor69; 09-24-2013 at 09:00 AM. Reason: add code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •