Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safely remove an Android Activity

We all know how easily and safely to create a new Activity. Now I want to know how to remove an Activity from my project safely.

I've created some activity in my project and feel that they are now needless and I want to delete them. But if I delete manually these files:

  1. The activity's XML file in the /layout folder

  2. The activity's Java file in the /src folder

  3. The <activity></activity> portion from the manifest file

Then,

  • Will no other data related that activity stays in my project? What are those?
  • Is there any simple removal procedure like creating an activity in Eclipse?
like image 431
A. K. M. Tariqul Islam Avatar asked Nov 13 '13 07:11

A. K. M. Tariqul Islam


People also ask

How can I delete activity safely?

Right click on each of the file associated with the activity (in Android View), select refactor, then select safe delete. This will also tell you if there are any use (of that file) which makes it not safe to delete.

Can I delete an activity in Android Studio?

You can right click on an activity->Find Usages(Alt+F7). You will get a list of files where the activity is used in the project, and then delete.

How do I remove a view from my activity?

ViewGroup vg = (ViewGroup)(myView. getParent()); vg. removeView(myView); should do what you want as far as correctly removing the View from the Activity.


1 Answers

I found my answer. To remove an activity, let the name of the activity is activity:

  1. Remove the activity.java file from src folder (java/your.package.name folder for AndroidStudio)
  2. Remove the activity.xml file from layouts folder (layout folder for AndroidStudio)
  3. Remove the activity.xml file from res/menu folder (this is an optional folder)
  4. Remove the <activity></activity> block of the activity from the manifest file
  5. If the <activity> block in the manifest file has a reference (usually in android:label tag) remove the referenced value (usually from values/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

like image 184
A. K. M. Tariqul Islam Avatar answered Oct 18 '22 12:10

A. K. M. Tariqul Islam