Tag Archives: Android

Fragment isAdded() vs getActivity()

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.


IntelliJ Android – Build a library project – jar file

In order to build a jar file from a project,

1. Open IntelliJ Module Settings

2. Navigate to “Artifacts” on the left most tab

3. In the Details section (right most section), be sure to specify an output directory for the jar

4. Rebuild the project. Select Build -> Build Artifacts -> Rebuild.