【发布时间】:2018-06-25 05:34:25
【问题描述】:
我有一段代码要循环运行,以便将实时数据从中获取到我的片段中。
我如何使用AsyncTask 实时获取 RAM 消耗,因为我不想让我的 UI 线程为此忙碌。
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(memInfo);
String TotalRam = String.valueOf(memInfo.totalMem);
int totaLram = Integer.parseInt(TotalRam);
String freeRam = String.valueOf(memInfo.availMem);
int freRAm = Integer.parseInt(freeRam);
【问题讨论】:
-
如果我将它运行到一个循环中以实时获取数据,它将阻塞 UI 线程,这就是为什么我想使用 AsyncTask 但我对此很陌生并且之前从未使用过它需要一些指南来制作它完成
标签: java android performance android-fragments