What does #SuppressWarnings("deprecation") do in Android? - android

I don't know about it completely. I think that it allows the deprecated code to be compiled. I want to know if the code under this line will always be run or not and does it depend on the software like Eclipse, studio you are working on?

Check this out.
Using suppresswarnings just tells the compiler not to warn you. It's still valid to use deprecated code, but usually there's a better way you should use instead.

The code will be compiled with or without it. It tells your IDE not to even warn you about it. Sometimes you have a good reason for using deprecated code. Putting this on those functions/classes reduces the number of warnings reported, which makes it easier to find important warnings of real problems.

Disables compiler warnings... In this case, deprecated code... Just for your information, for show clean code

Related

Any way to see all the methods that don't work at once? Android Studio

I have to estimate the time it takes to update a specific application made for Android 4.4 to Android 10 and I need to see all the methods that are deprecated or not working. Is there any way to see the methods without going file by file? (I'm using Android Studio with Java)
When I build the application I only get one or two types of error at a time, when I correct them I get another one and so on.
Thanks and best regards.
P.S: How long does it take you to update something like that? I'm a junior and I'm a little lost doing this.
Here, go to Analyze -> Inspect code. After inspecting check maturity there you will have depreciated methods. (Don't forget to change minSdk)
After you will do that it give you method with a warning and you can filter it by having API not support warning

Turn off Android Studios bad style advice?

I need to remove all of Android Studios "This can be changed to" warning flags. I know I can reduce all the warning flags with the slider from inspections to Syntax.
I don't know if Syntax covers every non style warning, or if it also includes actual warnings. If it does, can you link me the documentation that says so? I need actual hard proof. I can't find much talking about the syntax warning highlighting.
I can ignore these, no problem but I'm seeing that my team is treating these like real warnings. When you take an existing code base and a team.. we waste a ton of times with hundres of personal style errors. I like to do if(boolean == false), Because it's CLEAR. A lot of these suggestions make the code, bleedin edge 1980s style, save every character efficient, but as readable as.. well.. 1980s code..
For example, we just spent half an hour trying to figure out if we had an error in an if statement, because it "could" have simplified it sorta.
Or my favorites where it tells you to change it, then tell you to change it back..
Also yes I know I can add suppressions, which cause errors in my coworkers Eclipse. . .
See if this helps, Preferences → Editor → Inspections,
Disable the those you don't want, eg. Pointless boolean expression under "Control flow issues"
reference: https://www.jetbrains.com/idea/help/disabling-and-enabling-inspections.html
You can also add this line above the pointless boolean you want to ignore. I use this a lot when using BuildConfig variables as they appear constant but are really not as they are controlled by the gradle build system.
//noinspection ConstantConditions,PointlessBooleanExpression

Warning in Android

I created an app which runs without any problem
But it contains lot of warnings
Here my question?
What problem will arise when app contains a warning
Thanks in advance
I usually use the warnings to clean up my code in the following manner:
They tell us which variables are never used locally. Hence, DELETE them.
Use of deprecated stuff in android, hence keeping my code up-to-date.
Removing unused imports.
Useless assignments to variables.
Errors in Manifest like not setting "allowBackup=true/false"
etc etc...
No errors, but only warnings, means your code will run well. But the code may not be the best.
The difference in an error and a warning is that an error doesn't allow the code to be compiled. A warning on the other hand is a message from the compiler telling that you have something weird or unnatural in your code, but it's still able to compile.
A warning should be interpreted as "this is weird, but if you know what you're doing, then it's OK".
For example, pointer casting (from one object type to another object type) is a common source of warnings, but if you know what you're doing and you're confident it will not fail, you can ignore it.
Warnings are not errors, and as others have said, if you know what you are doing you can ignore them. But remember that warnings are the compiler trying to help you, and programming can be difficult enough that you should be grateful for any help you can get. A good way can be to ignore only those warnings that you know exactly what they are caused by, and be very suspicious of any others. And always try to get rid of all the warnings, so the important ones don't get lost among all the unimportant ones.
Warnings are only indicators that there's something wrong, but this something isn't critical for running your app. Sometimes it's just that an imported code isn't used at all, another time it's a hint that a code can throw a NullPointer that you aren't catching right now. But summing up, warnings are not critical - at least during development time.
So far, you should only care about the errors that will prevent you from compiling your app.
It depends upon the types of warnings you have. If you have Deprecated Warnings then
You can configure the Java Compiler to ignore the Deprecated Warnings. I'd suggest to configure this setting for the specific project, not globally. To do so, right-click on your project and go to Properties > Java Compiler > Errors/Warnings. Click Enable project specific settings and then unfold Deprecated and restricted API and select Ignore for Deprecated API.
This will disable all deprecated warnings though.

What is the difference between LogCat and LogCat(deprecated)?

I use eclipse to develop apps. When I goto eclipse's menu window->show view->other, I find two items nameed "LogCat" and "LogCat(deprecated)". What is the difference between LogCat and LogCat(deprecated)? I find when an application is running, they show the same logs.
LogCat was provided in ADT 4.0 or above, just add some new features. LogCat(deprecated) was the old version.
Deprecated means that at some point it will most likely stop functioning, you can still use whichever one you prefer until that happens .
I used both logcat and logcat(deprecated), and i did not found any difference except font and some details :)
Use of deprecated is the same like in any language. It's old and won't get support or won't have any improvement in that. In this case, theoretically Logcat should have or will have more/better features.

Does UCDetector work for android projects?

I've got an android project that I started from an old standard Java project, so because of the vast difference in target platform, I have a lot of dead code to cleanup.
I've seen UCDetector recommended for finding unused public methods in java projects in Eclipse. I installed it as directed, and it just doesn't show up on the menu, and I have no idea how to get it to work.
Has anyone got this combo to work, or have another recommendation? Or know how to get it to show up?
(I've tried Find Bugs which found some good stuff, but it doesn't find unused public code.)
Big warning!
It might partially work, but beware, cause it doesn't seem to know about XML-defined callback functions.
If you have installed a callback function on a widget, say a button in an XML Style Sheet, and it is not called in code, UCdetector will think it has 0 references, and suggest it deleted. This obviously is wrong, and will render your code uncompilable.
There might be other similar issues, related to Android specifics.
Viggo
Yes, UCDetector works for android projects. I just installed it and it works.
It's available in context menu of project in Package Explorer.

Categories

Resources