问题描述
我正在尝试调试 WearOS 手表之间的缓慢同步,该手表记录步数并将其作为消息通过蓝牙发送到其配套的 Android 应用程序?将其存储到 SharedPreferences 时会有延迟,有时它甚至不会更新,直到手表发送下一条消息并通过电话接收。在记录收到并存储在应用程序中的结果时,它会显示最新的结果,但视图不会刷新以使用进来的新数据更新 UI。 需要使用此类更新步骤视图。我认为即使接收到步数,UI 也不会更新。
public class ActivityRecord extends Activity {
TextView step_count;
TextView sitting_duration,sitting_title;
TextView distance_cover;
TextView walk_value;
ImageView walk,step,distance_covr,sitting;
ImageView maintenence,men_badge;
TextView men_text;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_record_updated);
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
SharedPreferences pref = getApplicationContext().getSharedPreferences("StoretodayDate",MODE_PRIVATE);
String dateNow=pref.getString("todayDate",null);
walk=(ImageView) findViewById(R.id.progress_walk);
step=(ImageView) findViewById(R.id.progress_step);
distance_covr=(ImageView) findViewById(R.id.progress_distance);
sitting=(ImageView) findViewById(R.id.progress_sit);
Picasso.with(this).load(R.drawable.progress_walk).into(walk);
Picasso.with(this).load(R.drawable.progress_step).into(step);
Picasso.with(this).load(R.drawable.progress_distance).into(distance_covr);
Picasso.with(this).load(R.drawable.progress_sedentary).into(sitting);
walk_value=(TextView) findViewById(R.id.walking_val);
step_count=(TextView) findViewById(R.id.step_count_val);
sitting_duration=(TextView) findViewById(R.id.sitting_val);
distance_cover=(TextView)findViewById(R.id.distance_covered_val);
step_count.invalidate();
if(date.equals(dateNow)){
// setting walk_value
SharedPreferences sharedPreferencesForActivityRecord = getSharedPreferences("activity_val",MODE_PRIVATE);
float testWalk= sharedPreferencesForActivityRecord.getFloat("walk_duration",0);
float testStepCount=sharedPreferencesForActivityRecord.getFloat("step_count_value",0);
float testSitting=sharedPreferencesForActivityRecord.getFloat("sitting_duration",0);
int heartRatetoStore=sharedPreferencesForActivityRecord.getInt("heart_rate",0);
int Sit_sec = (int) testSitting % 60;
int Sit_min = (int) ((testSitting / 60));
Log.d("Phone: "," Walk Value Before Calculation: "+testWalk);
int Walk_sec = (int)testWalk % 60;
int Walk_min =(int)(testStepCount/110); //(int)((testWalk / 60));
// walk value
// String valuetoPutWalk=String.format("%d Min %d Sec",Walk_min,Walk_sec);
String valuetoPutWalk=String.format("%d min",Walk_min);
if(stepValuetoSet!=0){
walk_value.setText(valuetoPutWalk);
}else{
walk_value.setText("0");
}
//setting sitting duration;
String sitting_value=String.format("%d min",Sit_min);
sitting_duration.setText(sitting_value);
float in_mile=(float) (testStepCount/2000);
String dis_in_mile=String.format("%.2f miles",in_mile);
distance_cover.setText(dis_in_mile);
}else {
SharedPreferences.Editor editor2 = pref.edit();
editor2.putString("todayDate",date);
editor2.commit();
SharedPreferences.Editor editor21 = getSharedPreferences("activity_val",MODE_PRIVATE).edit();
editor21.putFloat("walk_duration",0);
editor21.putFloat("sitting_duration",0);
editor21.putFloat("step_count_value",0);
editor21.commit();
walk_value.setText("0 Min");
step_count.setText("0");
sitting_duration.setText("0 Min");
distance_cover.setText("0 miles");
SharedPreferences.Editor editor = getSharedPreferences("set_goal",MODE_PRIVATE).edit();
editor.putInt("walk_target",0);
editor.commit();
}
}
public void refreshScreen(View view){
Intent intent=new Intent(this,ActivityRecord.class);
intent.putExtra("from","ActivityRecord");
startActivity(intent);
}
public void timeRemainButtonClicked(View view) {
Intent intent=new Intent(this,RemainingActivity.class);
intent.putExtra("from","intervention");
startActivity(intent);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)