奇葩6: android中sharedpreferences内容,在调用计时器后,被清空

现象:

正常流程:

答题开始之前,先检查是否有录音录像权限(结果记录到sharedpreferences中),然后定位(开启自定义CountDownTimer每秒钟检查定位结果),然后进入答题。

1. 当不需要定位的时候,sharedpreferences最终是有记录的。

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <boolean name="55126f22585729fdc4c96bf2_video" value="true" />
    <boolean name="54cecf63585729fdc4af61f3_video" value="true" />
</map>


2. 当需要定位的时候,sharedpreferences最终内容为空。

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map />

由于这两个操作是完全不搭嘎的,比较难理解。

在debug中发现,当准备调用定位的计时器时,此时sharedpreferences中还是有值的

// 可以开启定位,等定位,1分钟,每1s检查一次
					mc = new MyCount(locationWaitingMinute * 1000, 1000);
					mc.start();

在MyCount的第一次onTick中,sharedpreferences就被清空了

/* 定义一个倒计时的内部类 */
	class MyCount extends CountDownTimer {
		public MyCount(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);
		}

		@Override
		public void onFinish() {
			Log.d(TAG, "count down finish");
			if (baiduClient != null) {
				baiduClient.stopLocation();
			}
		}

		@Override
		public void onTick(long millisUntilFinished) {
			Log.d(TAG, "on Tick");
			String text = getString(R.string.locate_loading_first);
			String textFormat = String.format(text, locationWaitingMinute
					- millisUntilFinished / 1000);
			progressDialog.setProgressText(textFormat);
			if (receivedGPS) {
				this.cancel();
			}
		}
	}

目前未找到原因。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值