Is there a way to find my usages of certain shared preferences?
You can't 'Ctrl + Click' them since they aren't methodes or variables and can't select them or use the find usages function from androidstudio.
I can use the find usages on the getBoolean() method, however this gives me every single shared preference instead of just the one i am looking for.
You can find the key of SharedPreference by just Ctrl+Shift+F or click on Edit -> Find -> Find in path .
Select the desired module where you want to search and you are good to go .
There is no special support for this in Android Studio. You need to do a regular text search for getBoolean("preferenceName".
Search for
getSharedPreferences("pref_name"
in Edit -> Find -> Find in Path...
This will display occurences where you used that specific SharedPreference.
Related
I am doing translations on android studio and now I need to replace some strings that I had wrongly translated. When I search using CTRL+SHIFT+F I indeed get all occurrences but when I use the replace shortcut CTRL+SHIFT+R and try to replace I get a quick popup saying Occurrences in project configuration files are skipped then there is a button which says Include them. When I click that button, the find window opens then nothing happens. How do I search and replace from the ENTIRE project including the configuration files?
Select string and use Alt+Shift+R as Eclipse shortcut and Refactor your string, like below screenshots.
There really is no point in editing config files (because all of them are generated by Android Studio) so just don't click the button on the popup you described.
If I am mistaken then tell me what kind of config files you might want to edit.
Edit -> Find -> Replace in path
and then In Project
In Android Studio:
Edit -> Find -> Replace in path
I am looking for an efficient method to find and replace in android studio. where I can find a string using regex and replace the selected string with its substring.
e.g.
constants.LOG_FILE_PATH -> SETTINGS['LOG_FILE_PATH']
constants.LOG_DIR -> SETTINGS['LOG_DIR']
I have following regex for find
constants.[A-Z_]*
which selects constants.LOG_FILE_PATH and constants.LOG_DIR
but how to modify the replace string so that the above strings can be replaced by SETTINGS['LOG_FILE_PATH'] and SETTINGS['LOG_DIR'] respectively. I have to find and replace many strings in my project so manual find and replace is little overhead.
Edit 1: If you know how to do in pycharm or intellij-idea it will work in android studio also, thats why i have added tags pycharm and intellij-idea
Perhaps look at Structural Replace. Use the Find Actions shortcut (CMD + Shift + A) and type structural and the option should appear.
I guess something like the following may work:
Search template
constants.$log$
Replacement template
SETTINGS["$log$"]
Disclaimer, this is untested.
In Eclipse, I can put my cursor on a method name and hit ctrl-space and I get a list of available template proposals.
In Android Studio, when I'm typing a method name and open paren, I get a list of template proposals, but afterwards, how do I see the list again? I've already got show quick doc on mouse move, but that only shows the method signature I selected at first. I want to see alternatives to what I selected the first time through.
How do I show alternative method signatures, aka alternative template proposals?
EDIT:
Thanks to AndroidMechanic for answering Ctrl-P.
Here is what it looks like in Android Studio:
Here is what it looks like in Eclipse: . Notice that you're presented with the documentation in Eclipse, which I find helpful. But Ctrl-P gets me most of the way there.
In android studio to see all method overloads click inside the parenthesis and hit Ctrl + P. This will show you the different combinations you could pass as parameters to a method.
In Android Studio, I sometimes have to rename some field, attribute or method name.
I know I must select its name, then hit Alt+Shift+R. Then I type in the new name, and hit Enter.
However, sometimes it works, and sometimes... it just does nothing at all. The new name is just discarded and replaced with the old ones.
Can someone explain me why and how to force this very basic feature to work ?
I suspect that you've missed the refactor preview window that shows up when AS finds some code that it doesn't know if it should be refactored or not. For example, if the method being modified is referenced in comments, then AS will ask if you want to refactor those comment as well.
using a shortcut for "Rename" Variable Shift + F6
or
Select Variable/Method name -> Right Click in java file -> Refactor -> Rename
This also happens when using dagger and trying to refactor via Shift+f6. Android Studio hesitates when renaming things in generated code (which seems silly). Anyway, doing a project clean and then doing the rename works.
Alt+Shift+R replace a selected String (in your case the selected field, attribute...) and doesn't rename the variable, field... itself.
The feature I use for that task is Rename (not Replace). To achieve that you can either use Shift+F6 or right mouse click > Refactor > Rename. Now it changes the name also in other classes (if necessary).
For me, every time I refactor>rename it was showing me the usages and I changed them manually, but the name of the java class stayed the same, even I changed all the usages.
Finally, I unticked all the boxes, and it worked.
For some reason auto complete no longer works. for example when writing code using the android bitmap class, when i use the dot operator eclipse would suggest methods for that object instance. how do you turn this feature back on?
thanks mat.
I had this same problem. Here is how I solved it.
In Eclipse go to
Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced
And check the boxes labeled "Java Proposals" and hit Apply.
Im my case was API tools proposals the option that cause my autocomplete doesn´t work, here are the 4 default options that must be checked...
API Tools Proposals.
Java Proposals.
SWT Template Proposals.
Template Proposals.
the next time i must be careful when click Ctrl+Space =D
Go to Preferences > Java > Editor > Content Assist and paste "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz." (note the dot after z) into the "Auto activation triggers for Java:" field.
This worked for me ! Now as i type I get autocomplete options
Here's another solution I dicovered:
I would check the other solutions listed here first and if all else fails shut down eclipse then delete the file 'org.eclipse.jdt.ui.prefs' found in the workspace directory (Workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings).
Seems in my case the workspace became corrupted somehow and this fixed it. Haven't yet noticed any adverse effects by doing this.
eclipse use "ctrl+[space]" to show the "css/html/java proposal"
I had the same problem and none of the solutions here worked. For some reason, my Scheme had changed from "default" to "Emacs". So to fix it, I had to go:
Preferences> General> Keys and change the scheme back to default.