Monday 2 July 2012

How to debug extras from an Activity Bundle.

As far as I can tell, there's no simple call in Intent or Bundle to easily debug an Intent's extras.

Here's a bit of code you can use to get the list of extras you've passed to the Activity.

public String debugIntent()
{
    Intent intent = getIntent();

    String result = "";

    Bundle extras = intent.getExtras();
    if (extras == null)
    {
        return "no extras";
    }
    else
    {
        result += "key count: " + extras.keySet().size();
        for (String key : extras.keySet())
        {
            result += "\n" + key;
        }
    }

    return result;
}

This will give you a String that will list each of the extras you have supplied to the current Activity.

No comments:

Post a Comment