安卓第一行代码学习 The application may be doing too much work on its main 问题。求助

皆灾 2018-01-19 03:09:19
最近在学习大神的第一行代码,发现总是提示The application may be doing too much work on its main thread.这个错误。开始没太在意,因为就安卓模拟器的运行来说,有些小例子是可以测试的。但是最近看到了返回数据在logcat中看,但是由于提示The application may be doing too much work on its main thread.这个错误,总是不能看到logcat的值

01-19 04:14:52.720 2830-2858/com.example.activitytest D/OpenGLRenderer: endAllActiveAnimators on 0x8f0e1880 (RippleDrawable) with handle 0x9bceaf90
01-19 04:16:23.037 2830-2830/com.example.activitytest I/Choreographer: Skipped 56 frames! The application may be doing too much work on its main thread.
01-19 04:16:27.238 2830-2830/com.example.activitytest I/Choreographer: Skipped 52 frames! The application may be doing too much work on its main thread.
01-19 04:16:33.055 2830-2830/com.example.activitytest I/Choreographer: Skipped 47 frames! The application may be doing too much work on its main thread.
01-19 04:16:35.288 2830-2830/com.example.activitytest I/Choreographer: Skipped 31 frames! The application may be doing too much work on its main thread.
01-19 04:16:36.370 2830-2830/com.example.activitytest I/Choreographer: Skipped 51 frames! The application may be doing too much work on its main thread.
01-19 07:02:23.004 2830-2830/com.example.activitytest I/Choreographer: Skipped 242 frames! The application may be doing too much work on its main thread.
01-19 07:02:28.840 2830-2830/com.example.activitytest I/Choreographer: Skipped 125 frames! The application may be doing too much work on its main thread.
这是logcat提示。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_layout);
Button button1 = (Button) findViewById(R.id.button_1);
button1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
startActivityForResult(intent,1);
}
});
}
这是FirstActivity中的更改

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_layout);
Button button2 =(Button) findViewById(R.id.button_2);
button2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new Intent();
intent.putExtra("data_return","Hello FirstActivity");
setResult(RESULT_OK,intent);
finish();
}
});
}
这是SecondActivity中的更改。

这个例子郭霖大神给出的打印信息是
com.example.activity D/FirstActivity:Hello FirstActivity


来论坛找了很多提示The application may be doing too much work on its main thread.这种的错误,发现都是很大规模的程序,那我这种小例子的测试怎么会提示这种呢?费解。求大腿指教一二,感激不尽。
...全文
1230 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
__椎名真白 2018-01-27
  • 打赏
  • 举报
回复
我当时自学的时候也是这个提示,一直logcat里面弹弹弹,百度结果就是不要在主线程做太多的耗时操作,耗时的交给子线程,避免主线程阻塞。不过你也不用管这个,完全没啥影响的,先学东西再说。
皆灾 2018-01-21
  • 打赏
  • 举报
回复
还是搞不清楚为什么,不过幸好的是我刚刚运行了一个空项目,没有提示这个问题。。
皆灾 2018-01-21
  • 打赏
  • 举报
回复
代码肯定是没有问题我觉得,因为我反复确认过。我是按照书上所说去选择了basic 或者选择empty都是会提示这个。 现在看到一百多页了,不管运行什么例子都提示这个。醉了,请问是安装环境有问题了么,还是我在创建项目的时候出现问题了
sadyYang 2018-01-20
  • 打赏
  • 举报
回复
不要在主线程做耗费时间多的工作,最好开个线程来做。
moonFY 2018-01-19
  • 打赏
  • 举报
回复
你贴出来的代码没有问题,问题在你没贴出来的代码中
  • 打赏
  • 举报
回复
这些看起来,貌似,没毛病
  • 打赏
  • 举报
回复
你看看你的Activity有没有定义跳转动画。。 最好把onActivityResult 的代码也贴下

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧