android中出现Only the original thread that created a view hierarchy can touch its views.错误解决方案
2013-11-15 22:14
591 查看
/** * kill the process onclick listener * @param view */ public void killProcess(View view){ int total = 0; long memorySize = 0; for (TaskInfo userTaskInfo : usertaskinfos) { if(userTaskInfo.isChecked()){ manager.killBackgroundProcesses(userTaskInfo.getPackName()); total ++; memorySize += userTaskInfo.getMemorySize(); } } for (TaskInfo systemTaskInfo : systemtaskinfos) { if(systemTaskInfo.isChecked()){ manager.killBackgroundProcesses(systemTaskInfo.getPackName()); total++; memorySize += systemTaskInfo.getMemorySize(); } } Toast.makeText(getApplicationContext(), "清理了"+total+"个进程"+"释放了" + TextForMater.getKBDataSize(memorySize)+"M内存", 0).show(); fillData(); }
在Activity中调用以上方法;
private void fillData() { setTitleData(); new Thread(){ public void run() { ll_task_manager_loading = (LinearLayout) TaskManagerActivity.this.findViewById(R.id.ll_task_manager_loading); ll_task_manager_loading.setVisibility(View.VISIBLE); provider = new TaskInfoProvider(TaskManagerActivity.this); taskInfos = provider.getAllTasks(runningProcess); Message msg = new Message(); msg.what = GET_ALL_TASK_FINISH; handler.sendMessage(msg); }; }.start(); }
kill方法中调用了子线程的方法,出错原因是ll_task_manager_loading是主线程中的对象,不能再子线程里调用,因为没其生命周期已经结束。
参考
相关文章推荐
- android开发中出现Only the original thread that created a view hierarchy can touch its views.错误的解决方法
- 【Android】错误信息 Only the original thread that created a view hierarchy can touch its views
- 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views. .
- Only the original thread that created a view hierarchy can touch its views错误
- Only the original thread that created a view hierarchy can touch its views的解决方案
- 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views.
- 关于Only the original thread that created a view hierarchy can touch its views的解决方案
- Android: Only the original thread that created a view hierarchy can touch its views 异常
- 关于Only the original thread that created a view hierarchy can touch its views的解决方案
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
- Android进阶——Handler的应用之解决Only the original thread that created a view hierarchy can touch its views
- 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用
- 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views.
- 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views.
- Android Only the original thread that created a view hierarchy can touch its views.
- 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用&用其更新UI
- android在工作线程中处理UI线程报错:Only the original thread that created a view hierarchy can touch its views.
- 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用
- 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用
- 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views.