Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "Safe Delete" in Android studio?

When I want to delete a class or a layout, I get a popup asking me do I want to "Safe Delete" it.

I wanted to know what exactly are all of the options, but i cannot find any nice answers out there.

So what do all of these three options mean exactly?

enter image description here

like image 270
SteBra Avatar asked Oct 09 '14 09:10

SteBra


People also ask

What does safe delete do?

The Safe Delete refactoring lets you safely remove files from the source code. To make sure that deletion is safe, PyCharm looks for the usages of the file being deleted. If such usages are found, you can explore them and make the necessary corrections in your code before the symbol is actually deleted.

What is safe delete with usage Search?

Safe delete IntelliJ IDEA lets you use the Safe Delete refactoring to remove files and symbols from the source code safely. Before IntelliJ IDEA deletes a file or a symbol, it searches for usages and if they are found, IntelliJ IDEA lets you check them to make necessary adjustments.

Is it safe to delete .idea folder in Android Studio?

idea/ are safe to delete, though I would have the IDE not be open on that project while you do it. If that is your only project, close Android Studio, then delete those directories using your OS file explorer or the command line. Then, reopen Android Studio, and it will recreate and re-populate those directories.


2 Answers

With safe delete Android Studio will search if your "WebViewA" is used in another file or not, so it won't cause any error if you delete it.

For example if you are using class WebViewA in MyActivity class and then you delete the WebViewA class without safe delete, there will be a new error in MyActivity class.

This is the example of safe delete :

I tried to delete BluetoothUtility class and I used safe delete and then Android studio detect there are 2 usages of BluetoothUtility

enter image description here

After selecting View Usages I can find that I used BluetoothUtility in MyActivity class. And I can also do refactor from it.

enter image description here

I hope my explanation is clear enough! :)

like image 60
Niko Adrianus Yuwono Avatar answered Oct 13 '22 02:10

Niko Adrianus Yuwono


Safe Delete works into Android Studio as same as other development environment based on IntelliJ IDEA.

It says that

You can safely remove classes, interfaces, methods, fields, and parameters, keeping the code working and error-free. The Safe Delete Refactoring finds all the usages of the selected symbol within the open project or simply delete the symbol if no usages found.

Ref : Re-factoring into IntelliJ


You can read more about at Safe Delete doc from IntelliJ

like image 27
Pankaj Kumar Avatar answered Oct 13 '22 01:10

Pankaj Kumar