简体   繁体   English

Android:如何每1秒从另一个活动中获取数据?

[英]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.

相关问题 如何从android中的Sqlite中获取数据。数据存储与一个活动同时获取另一个活动 - How to fetch data from Sqlite in android .data is storing with one activity while fetching another activity 如何每秒自动刷新我的Android活动中显示的数据 - How to auto refresh data displayed in my Android Activity every second 如何将数据从活动传递到另一个活动,然后再传递到Android上的另一个活动? - How to pass data from an activity to another activity and then to another activity on Android? 如何在另一个活动中从 SQLite 数据库中获取特定数据以在 Android 中登录? - How to fetch specific data from SQLite database in another activity for login in Android? 如何从联系人列表中获取所有数据并发送到Android文本框中的另一个活动? - How to fetch all the data from the contact list and send to another activity in a text box in android? 如何从Android中的另一个Activity保存数据? - How to save data from another Activity in Android? 如何将数据从一个活动传递到 Android 中的另一个活动 - How to pass data from one activity to another activity in Android 如何将数据从活动传递到Android上的另一个活动 - How to pass data from activity to another activity on Android 如何在Android中没有意图的情况下将数据从活动发送到另一个活动 - How to send data from activity to another activity without Intent in android android-如何将数据从服务发送到片段“每秒”? - android - how to send data from service to fragment “every second”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM