How to remove redundant casts in Android Studio? - android

I was targeting SDK version 21 or 22 in one or my old projects.But now I have updated to the latest SDK version. Now I can see a lot of redundant casts of views (As view casts are redundant now). Is there any alternate to remove all those redundant casts at once Via any short cut way rather going through each and every file and remove? I am using Android Studio version 3.2 now.

Pressing ctrl+shft+A will open action dialog. In it type clean in and from suggestion list select Code Cleanup. This will open a separate dialog from which you can select your relative scope. Select which option suits your need and press OK.

Right click on directory which you want clean up.
Select Analyze > Code Cleanup
Click OK.
Here you go!

Select Your Project folder or app (according to your project explorer view)
Select Analyze from menubar
choose option Code cleanup or silent code cleanup .
Where Code cleanup prompt you dialog with options like Project or module and silent code cleanup cleanup without displaying the Code Cleanup dialog. from currently selected project or module.

Related

Android SDK path not specified

I already installed the android studio but i am having a problem to proceed ahead,
and the problem is Android SDK path not specified, what does it mean, do i need to download something or what?Android SDK is having problem
Go through the following steps but first make sure your PC is connected to the internet.
Open your Android Studio
Go to the File menu and choose Settings
After that from the left side of Settings window search Android SDK, click on it and on right side click Edit.
Then from SDK Setup Window Click Next and Another window will be opened click Next.
Finally, the installation starts and Android Studio download the SDK and necessary files.
Yes, you need to download the Android SDK. Then you need to add the location on your computer to Android Studio.
The SDK can be downloaded by opening a workspace in Android Studio, and finding a button with an arrow pointing down. If you hover over it, it should say "Open SDK manager". Press it and download the packages you need.
Yes, Before installation it will ask you options.Just tick mark Android SDK.
See below:
Refer link: https://developer.android.com/studio/install
The installer is misleading making you think the SDK is already there. After much searching I figured this out:
Cancel the dialogue box asking for the Android SDK path and do the following:
Open Android Studio IDE. Find the down arrow icon, should be second last icon in the toolbar. Click that. You will see a path for Android SDK Location:. Click the edit link to the right of that. This will bring up the SDK Components Screen. If you can check the boxes there, check them. They may already be checked or they may be disabled. You can leave the path as is, for me its:
C:\Users\<user name>\AppData\Local\Android\Sdk
Depending on whether you had Android Studio before it may say it has detected a previous version and it will only download the components it needs. This is normal. Now click the NEXT button. A confirmation screen will come up with Setup Type and SDK Folder. If you want to change your SDK Folder this is your last chance, if not, click NEXT again.
It may bring up a Terms & Conditions screen, click the Accept radio button then NEXT. It will go and download the Android base SDK. When it's completed click FINISH.
You will then be taken to the Platforms screen where you can select which Android platforms you want to support. ie, Android 9.0 (Pie), Android 8.1 (Oreo). Select all the platforms you need then click APPLY.
The downloader will grab all those packages for you. Next, click the SDK Tools tab. Check the boxes of the tools you want and click APPLY. It may bring up a Terms & Conditions screen again, click the Accept radio button then NEXT. When completed just click FINISH and you're good to go.
File > Settings
The download will begin
In some cases, the project works properly but suddenly this error appears even though the project has nothing to do with Android
If this is your case, try the following steps:
Find a file in your project called tests.iml (or File ending in .iml)
file location in default is C:\yourProject\tests\tests.iml
Revert to the last version for all page by the click on the git change icon (1) and click on the revert button (2)
As the following image:
Run project

How do I see gradle tasks run by Android Studio?

I'm following the course "Developing Android Apps" on udacity.
I have a problem on Lesson4A with the test suite (TestUtilities) complaining "Task 'cleanTest' not found in root project 'Sunshine'.
And then it points me to run with --stacktrace option.
But I don't know how I can run the command on the terminal in the first place.
How can I see what gradle-tasks that android studio is running?
Thanks :)
At the bottom right corner of Android Studio you have different views:
Gradle console
Event Log
Additionally, if your Gradle is running, will appear a 3rd one where you can see a progress bar with some information about the process. But if you want a full details use the 2 first views.
I believe you have not do the configuration at first, as the default configuration is not appropriate for this project.
Select Edit Configurations next to Run button on toolbar
Make a testing configuration, by click the + button and select Android Test.
Make sure you choose "Show Chooser dialog" in target device section if you are using Virtual devise like Genymotion
Hit OK and press the run button.
PS. Make sure your have this configuration under Android Test, and nothing under JUnit dropdown.
I was confused at first, but not anymore after I tried above steps from Udacity notes.

Can't see errors/warnings in Problems view unless project is selected in Package Explorer

I can not see any errors or warnings in my Eclipse(4.4.2) unless I specifically select the project or file in Package Explorer and then go to the Problem view.
So far I tried different options in "configure contents" and "show" dialogs in the Problems view menu without success. The only time I see errors in the Problems view is if I set the options "show all" or "all errors" and then it shows every issue with every project I have, don't want/need that.
I also tried (following suggestions from other posts) closing/reopening project, Build Automatically and fix project properties... no luck.
I remember it used to be that if you had issues in a file you were currently editing you could jump straight to the Problems view and it would show you the issues for the project where that file lives, in other words the current project being edited. This is the result I want.
Android SDK manager is up to date so I am out of ideas. Appreciate any help.
Open the 'Configure Contents' menu and select the 'All Errors' (click the line don't use click the check box). You should then be able to configure the Scope of the errors on the right hand side of the dialog (such as any element in same project)

How to make Android Studio automatically suggest code fixes

When using Android Studio, I want to be able to just put the mouse cursor on top of a code word with a compiler error and get a drop down list with fix suggestions. Right now in order to open that list, I must press ALT + ENTER. How can I make Android Studio to open the list automatically when the coursor is above the error line?
In your Android Studio go to:
Settings > Editor > Code Completion and check in 'Autopopup code completion'
You might check as well the other options in the tab - e.g. delay in ms.
It seems that there was an update to the Android Studio and this feature was added. You need to play with the error line a bit (sometimes there's a need to press it a few times) and then you'll get the option to view code fixes.

Android project Refactor greyed out

I renamed a project in Eclipse via 'Refactor > Rename' as suggested in this answer.
I now want to rename it again, but the Refactor menu has only one menu item now (Android > Extract Android String...) which is also greyed out!
I am using Eclipse 3.6.1 with the latest Android SDK 9.
Why is that and how to I restore this to normal?
Update (1): After following Sankar Ganesh's suggestion (selecting a string), the Refactor menu appeared again. I then selected the Rename... menu item again and I received the following error message box:
This is much better than the previous situation, in which I had no idea why the Refactor menu had been disabled and what to do. Still, I don't understand why this is and what rules I should follow when using the Refactor function. I only wanted to rename a project... that's all. :)
Update (2): I just tried the same exact operation again again (Refactor > Rename while the project is selected in Project Explorer) and it worked! (without issuing the message box shown above).
What's going on?
Must be a bug, because this is clearly inconsistent.
I was wonder,why you struggling for Renaming a project,
if you want to rename your project, then simply you can select your project, then click refactor menu, then Rename, that's it
step1:
Step2: Now see My project name is updated,initally it was friend finder, now friendfinderupdated
Also , you can use Extract Android String for Valid Java Identifiers and not for packages and files, because see window here
Pls select a String in your java code and do that Refactor -> Android -> Extract Android String, now you can see dialog, what i had shown below
and see next image
Mystery solved!
The problem turned out to be that I was trying to 'Refactor > Rename' while in the Resource perspective.
Once I switched to the Java perspective, this (inconsistent) behavior didn't repeat itself and I was even able to check the Update references checkbox.
Wow!
(thanks #Sankar Ganesh for posting the snapshots, because that allowed me to notice that there is an "Update references" checkbox and that the text on your caption bar is different than mine)

Categories

Resources