Wrong Thread rule does not work normally?

Viewed 319

Recently, I have a task as define a new custom lint rule which is quite similar with Wrong Thread rule in the default Lint rules. Thus, I have been researching about Wrong Thread rule. However, when I just started to test Wrong Thread rule in Android Studio, it did not work normally as I have already read from the document. I will describe the problem as below:

  • First, I annotate a method which runs in UI Thread (named as "uiMethod()") with @UiThread annotation. Besides, another method (named as "workerMethod()") run in Worker Thread is annotated with @WorkerThread annotation.

  • Inside uiMethod(), I invoke workerMethod(). As normally, this code must be inspected as an error due to Wrong Thread lint rule in real time, then the IDE will highlight the line in red. This behavior is exactly what I expect.

But, the behavior of Android Studio in this case processes very weird:

  • When I finish typing "workerMethod();" ("finish" means I have already put the semicolon down), the line is highlighted and new error is showed immediately (this behavior is normal).

    Click to see image: the rule works

  • However, by the time I press enter to switch to the new line, the highlight and the error notification is both off, that means the error disappeared (absolutely strange).

    Click to see image: the rule does not works

  • Then, I try "Analyze -> Inspect Code" (manually inspect the code) to inspect the whole app module. The Wrong Thread error still does not appear although many other errors and warnings are showed.

  • Lastly, I utilize "Run Inspectation By Name" tool and input rule name: WrongThread. This time, the rule is triggered and the line "workerMethod();" is marked as error. (this tool worked perfectly but it does not meaningful for my task).

I also test in 2 other computers which are both installed Android Studio 3.6.1, everything is the same. Is this the bug of Android Studio or Lint framework? If it is, my task seems to be hopeless, cry cry.

Please help me, highly appreciate and thank you very much.

1 Answers

It actually appear to be a bug,in my case when i create a new activity the activity's class doesn't recognize the activity and deprecates it until i restart the android studio.

Another bug is with id's,when creating a new image view or textview or any other library the whole project doesn't recognize it and deprecates it.

I hope google fix these bugs soon.

Related