BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #15290同步于 2014/8/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖

[问题]求问大牛叔叔们,AsyncTask在Android4.4可以执行,在4.0,

HB0318
2014/8/2镜像同步9 回复
另外在4.4模拟器上可以顺利执行,得到想要的结果。 在4.1,4.0真机上执行得不到想要的结果。onPostExecute不执行? 跪求,调了好久,真机就是不行。 源码: 扫描sd卡,把视频文件列表形式到一个fragment。不知道为什么模拟器上可以实现,真机上就实现不了。 模拟器是4.4的,真机是4.0,4.1.求大牛们给知道下下,万分感谢。 public class FragmentFile extends FragmentBase implements OnItemClickListener { private FileAdapter mAdapter; private TextView first_letter_overlay; private ImageView alphabet_scroller; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); // ~~~~~~~~~ 绑定控件 first_letter_overlay = (TextView) v.findViewById(R.id.first_letter_overlay); alphabet_scroller = (ImageView) v.findViewById(R.id.alphabet_scroller); mListView = (ListView) v.findViewById(android.R.id.list); // ~~~~~~~~~ 绑定事件 alphabet_scroller.setClickable(true); alphabet_scroller.setOnTouchListener(asOnTouch); mListView.setOnItemClickListener(this); // ~~~~~~~~~ 加载数据 new ScanVideoTask().execute(); return v; } //...文件扫描task private class ScanVideoTask extends AsyncTask<Void, File, ArrayList<PFile>> { private ProgressDialog pd; private ArrayList<File> files = new ArrayList<File>(); @Override protected void onPreExecute() { super.onPreExecute(); pd = new ProgressDialog(getActivity()); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); pd.setMessage("正在扫描视频文件"); pd.show(); } @Override protected ArrayList<PFile> doInBackground(Void... params) { // ~~~ 遍历文件 eachAllMedias(Environment.getExternalStorageDirectory()); ArrayList<PFile> result = new ArrayList<PFile>(); for (File f : files) { String name = f.getName(); PFile po = new PFile(); po.title = name; try { po.title_pinyin =PinyinUtils.chineneToSpell(name.charAt(0) + ""); } catch (BadHanyuPinyinOutputFormatCombination e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } po.path = f.getPath(); po.last_access_time = System.currentTimeMillis(); po.file_size =f.length(); result.add(po); } Collections.sort(result, new Comparator<PFile>() { @Override public int compare(PFile f1, PFile f2) { char c1 = f1.title_pinyin.charAt(0); char c2 = f2.title_pinyin.charAt(0); return c1 == c2 ? 0 : (c1 > c2 ? 1 : -1); }//排序 }); return result; } @Override protected void onProgressUpdate(final File... values) { File f = values[0]; files.add(f); pd.setMessage(f.getName()); } /** 遍历sd卡文件夹,查找出视频文件*/ public void eachAllMedias(File f) { if (f != null && f.exists() && f.isDirectory()) { File[] files = f.listFiles(); if (files != null) { for (File file : f.listFiles()) { if (file.isDirectory()) { eachAllMedias(file); } else if (file.exists() && file.canRead() && FileUtils.isVideo(file)) { publishProgress(file); } } } } } @Override protected void onPostExecute(ArrayList<PFile> result) { super.onPostExecute(result); mAdapter = new FileAdapter(getActivity(), result); mListView.setAdapter(mAdapter); pd.dismiss(); } } //listview适配器 private class FileAdapter extends ArrayAdapter<PFile> { public FileAdapter(Context ctx, ArrayList<PFile> l) { super(ctx, l); } @Override public View getView(int position, View convertView, ViewGroup parent) { final PFile f = getItem(position); if (convertView == null) { final LayoutInflater mInflater = getActivity().getLayoutInflater(); convertView = mInflater.inflate(R.layout.fragment_file_item, null); } ((TextView) convertView.findViewById(R.id.title)).setText(f.title); ((TextView) convertView.findViewById(R.id.file_size)).setText(FileUtils.showFileSize(f.file_size)); // return convertView; } } public final class PFile { public long _id; public String title; public String title_pinyin; public String path; public long last_access_time; public int duration; public int position; public String thumb; public long file_size; }
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
icyfox机器人#1 · 2014/8/2
.
HB0318机器人#2 · 2014/8/2
大牛哥别闹,给看看呀,。么么哒 【 在 icyfox 的大作中提到: 】 : .
hfaltgg机器人#3 · 2014/8/3
你起码把错误信息贴一下吧
longfloat机器人#4 · 2014/8/7
楼主你的注释真个性
HB0318机器人#5 · 2014/8/8
为嘛呀,人家是菜鸟,求别嘲笑,呜呜 【 在 longfloat 的大作中提到: 】 : 楼主你的注释真个性 来自「北邮人论坛手机版」
coolfile机器人#6 · 2014/8/9
把PFile类实现下串行接口 通过『我邮2.0』发布
HB0318机器人#7 · 2014/8/11
叔,串行接口是implements Serializable吗?我implements Serializable,还是不成呀。 【 在 coolfile 的大作中提到: 】 : 把PFile类实现下串行接口 : 通过『我邮2.0』发布 来自「北邮人论坛手机版」
coolfile机器人#8 · 2014/8/11
mainfest写读写文件的权限了吗? 关于扫描sd卡文件,给你个参考示例吧 https://github.com/iPaulPro/aFileChooser
HB0318机器人#9 · 2014/8/11
写了,就是在模拟器上ok,在真机上不行。是不是模拟器耗时长,真机耗时短,异步任务没来得及执行完全? 【 在 coolfile 的大作中提到: 】 : 写读写文件的权限了吗?