[英]Android: How to fetch data every 1 second, from another activity?
I have a timertask like this one: 我有一个类似这样的计时器任务:
<code>
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
updateGraph(.....);
}
},0,2000);
</code>
But here within the updateGraph method i want to pass the Y-value. 但是在updateGraph方法中,我想传递Y值。 This Y-value is read thru another TimerTask in another activity, is this possible?
通过另一个活动中的另一个TimerTask读取此Y值,这可能吗? Read every second from the other activity ?
阅读其他活动的每一秒钟?
/Mikael /的Mikael
Instead of Passing it through Method EveryTime 而不是通过方法EveryTime传递它
Declare a public static variable and update it at Regular Frequency in Your FirstActivty in TimerTask Method 在TimerTask方法的FirstActivty中声明一个公共静态变量并以固定频率更新它
public static double Y;
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
//update Y here
updateGraph(.....);
}
},0,2000);
In Second Activity's Timer Task use 在Second Activity的Timer Task中使用
FirstActivity.Y
持续更新Timer()中活动A和活动B中SharedPreference中的Y值。从SharedPreference中读取相同的Y值。
This issue solved! 这个问题解决了! Thanks all, used: public static values between the activites!
谢谢大家使用:活动之间的公共静态值!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.