这个问题在这里已有答案:
我是android的新手 . 我以前写了一些应用程序,它们都运行良好 . 但是,这个应用程序运行速度非常慢 . 例如 . 当我点击设置时,需要4秒才能显示 . 这是日志
I/Choreographer: Skipped 41 frames! The application may be doing too much work on its main thread.
I / Choreographer:跳过42帧!应用程序可能在其主线程上做了太多工作 . I / Choreographer:跳过53帧!应用程序可能在其主线程上做了太多工作 . I / Choreographer:跳过89帧!应用程序可能在其主线程上做了太多工作 .
我的活动非常简单 . 它只是检查用户是否登录 . 然后它将获得SharedPreferences上的用户名
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNotLoginTextView = (TextView) findViewById(R.id.notLoginTextView);
prefs = getSharedPreferences(STUDENT_PREFS, 0);
int id = prefs.getInt("studentId", 0); // if not, id = 0
if(id == 0)
{
mNotLoginTextView.setText(R.string.not_login);
mNotLoginTextView.setEnabled(true);
}
else
{
String lastName = prefs.getString("lastName", null);
String firstName = prefs.getString("firstName", null);
mNotLoginTextView.setText("Have a nice day " + firstName + " " + lastName);
mNotLoginTextView.setTextSize(18);
}
}
谢谢您的帮助 .
更新:关于at the link above问题的答案不适用于我的案例
我没有使用片段来创建设置菜单,因此它导致了这个问题 . 为设置菜单创建片段后,它比以往任何时候都更快 .
1 回答
对于此解决方案,请确保应用程序没有在后台运行不必要的服务 . 并避免mutation的数据 . 增加heap size .