zhouguangfu09 / stepcounter Goto Github PK
View Code? Open in Web Editor NEWA small example about android pedometer
A small example about android pedometer
你好,请问不是从服务中返回数据给Activity要使用一些手段,如回调什么的,这里在StepCounterActivity类中为什么直接就能访问到StepDetector类中通过传感器得到的数据?像下面这样:
`
if (thread == null) {
thread = new Thread() {// 子线程用于监听当前步数的变化
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
int temp = 0;
while (true) {
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (StepCounterService.FLAG) {
Message msg = new Message();
if (temp != StepDetector.CURRENT_SETP) {
temp = StepDetector.CURRENT_SETP;
}
if (startTimer != System.currentTimeMillis()) {
timer = tempTime + System.currentTimeMillis()
- startTimer;
}
handler.sendMessage(msg);// 通知主线程
}
}
}
};
thread.start();
}
`
还有这样:
private void countDistance() { if (StepDetector.CURRENT_SETP % 2 == 0) { distance = (StepDetector.CURRENT_SETP / 2) * 3 * step_length * 0.01; } else { distance = ((StepDetector.CURRENT_SETP / 2) * 3 + 1) * step_length * 0.01; } }
谢谢您的回答
下載後不能直接在ANDROID STUDIO 打開, 是要我們自己放進去??
不能在后台运行啊,我把手机关屏再打开,或者是切换其他应用再回来,数据就会被清零
手机静止放在桌子上,照样走呢
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.