Safely remove an Android Activity
I found my answer. To remove an activity, let the name of the activity is activity
:
- Remove the
activity.java
file fromsrc
folder (java/your.package.name
folder for AndroidStudio) - Remove the
activity.xml
file fromlayouts
folder (layout
folder for AndroidStudio) - Remove the
activity.xml
file fromres/menu
folder (this is an optional folder) - Remove the
<activity></activity>
block of the activity from themanifest
file - If the
<activity>
block in themanifest
file has a reference (usually inandroid:label
tag) remove the referenced value (usually fromvalues/strings.xml
).
According to answers from @ojonugwa ochalifu and @Md Tarik Mahmud you should also right click on app folder then Refractor -> Remove Unused Resources
Just do it in a two steps in Android Studio.
- Delete the Activity's Java file: YourActivity.java
- Select app from the Project-Browser in Left Panel. Click Refactor from menu, click Remove Unused Resources.
You are done.
I don't think there is any procedure to delete an activity at once from everywhere.
Delete the entry from manifest first. Then delete the Activity class file. Once class file is deleted you will start getting errors where it is used. Look into each error separately and resolve them.
And the title string in res/values/xml/strings.xml