我需要每 5 分钟后在设备存储中记录“一些文本”,有人可以指出我执行此操作的最佳方法。但我不希望主线程冻结,并且日志线程应该一直处于活动状态。我试过这个,但它似乎冻结了我的模拟器有没有更好的方法来做同样的事情
public class DataWriteService extends Service {
private FileIOHelper fileHelper= new FileIOHelper("Test.txt");
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//Gets location and writes to a file
fileHelper.writeToFile(this, "Some text");
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
}
}