A great WordPress.com site

In Android fragments, its a common practice to check if the fragment is still attached to the activity before performing some action, to avoid IllegalStateException. There seem to be several similar ways to achieve this. Checking if getActivity() == null is one way. However a more reliable way seems to be to use isAdded(). This internally checks if the activity is not null, as well as checks if the current fragment is added to the activity.

While implementing a complex UI layout in Android, it is very useful to get a good picture of the bounds (the border) of different components within the UI. For instance, if a relative layout’s position is modified programmatically, getting the bounds of the relative layout is useful. This helps in figuring out if a layout’s final position in the screen is in harmony with the expected position of the layout in the UI design. This also gives a good visual indicator of the distance between components when (say) RelativeLayout.below is specified.

In order to do this, turn on developer mode in Android. Then select Settings -> Developer Options -> Show layout bounds. This will draw blue rectangles on every UI component for all applications.

// Filter to only show results that can be “opened”, such as a file (as opposed to a list
// of contacts or timezones)
intent.addCategory(Intent.CATEGORY_OPENABLE);

// Filter to show only images, using the image MIME data type.
// If one wanted to search for ogg vorbis files, the type would be “audio/ogg”.
// To search for all documents available via installed storage providers, it would be
// “*/*”.
intent.setType(“image/*”);

The above error arises when the content provider has been declared incorrectly in the manifest.
1. Make sure that this is defined WITHIN the tags

In the above, android:authorities is just the name of a string that should be unique. Its different from the android:name, which is the fully qualified name of your ContentProvider implementation that implements android.content.ContentProvider

2. Although the actual content provider implementation may reside in a library project, the definition should be reside in the androidmanifest.xml of the main project.

It is not sufficient to merely extend the android.app.Application class – the fully qualified name (see below) needs to be defined in the androidmanifest.xml in order for the onCreate() method to get called back by Android.

Notice the “View Source” link right next to the TextView title. Click on it to go to the class implementation.
Follow similar steps to look at resource source code. The beauty of this is that the tool will navigate you to whichever repo the source code is located in – you don’t have to do this yourself.

I found this when trying to see how they implemented the InputFilter class for the EditText component.