I have a background in Java and recently, I'm learning about Java in Android so the question might seem to be overwhelming for a newcomer like me. Anyway, here are the questions (in italic).
I created a project using a template (Phone and Tablet - Empty Activity), then used Layout Editor to add 2 Plain Text to the GUI. After that, I added some code to MainActivity.java (there is nothing else in the class).
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText equation = findViewById(R.id.textEquation);
equation.setEnabled(false);
EditText result = findViewById(R.id.textResult);
result.setEnabled(false);
}
public void onBtnClick(View theView){
EditText equation = findViewById(R.id.textEquation);
EditText result = findViewById(R.id.textResult);
}
When I ran the program, I got this warning: I/Choreographer: Skipped 31 frames! The application may be doing too much work on its main thread.
As the answers shown in these links: The application may be doing too much work on its main thread and The application may be doing too much work on its main thread. how to fixed it. This might not be a real issue as I'm using an emulator and the code/resource are from a template, which might not be optimal.
However, what exactly determines the term "too much work" here? When I comment out the two lines in onBtnClick
, the warning goes away. Although I'm using an emulator, findViewById()
is considerably "heavy" enough to generate the warning. I know 60 fps (16ms per frame) is the standard, but it still does not answer my question.
Besides, can someone simplify the main thread/method doing right now (in my case)? I'm aware that the main
class/thread in Android is different than in regular Java programming (as answered here).
Concept wise, is the main threads completely different than threads for UI (like using invokeLater
in Java Swing)? I guess it is, as the Google document suggests "As such, the main thread is also sometimes called the UI thread. However, under special circumstances, an app's main thread might not be its UI thread; for more information, see Thread annotations."
Update
- (09/30) For the question that I striked through, now that I've read more about Activity life cycle, I start to have a sense of what's going underneath. However, I'm still finding answers for the two italic question.