如何在Android应用程序中保存实时数据以便以后查看?

时间:2014-06-30 17:29:22

标签: android

我正在创建一个使用EEG NeuroSky耳机的应用程序,该耳机测量用户在玩游戏时的特定时间段内的注意力和中介级别。

从耳机记录关注和调解级别,并每秒在屏幕上实时显示(0到100之间的整数)。它与神经网络应用程序非常相似here

我希望能够保存它们,然后在游戏结束后在单独的Activity中查看它们,无论是int值还是图形形式。即能够查看用户调解级别为36秒,注意级别为45秒等等。

是否可以这样做,如果是这样,怎么做?

特定关注领域:

注意 - 我不知道如何保存每个msg.arg1的值?

case TGDevice.MSG_MEDITATION:
                meditation.setText("Meditation: " + msg.arg1 + "\n");

                if(msg.arg1<=35){

                    //if mediation level is low it turns red
                    meditation.setBackgroundColor(Color.RED);

                }else if((msg.arg1<=70)&&(msg.arg1>=35)){
                      meditation.setBackgroundColor(Color.YELLOW);
                    }else{

                        meditation.setBackgroundColor(Color.GREEN);
                    }

                break;

记录数据的代码:

/**
     * Handles messages from TGDevice
     * 
     */
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            // msg.what determines the type of each message
            switch (msg.what) {
            case TGDevice.MSG_EEG_POWER:

                //WILL NEED TO CHANGE TO PUTPUT TO SCREEN. 
//              Log.d("LSD", "highAlpha: " + eegPower.highAlpha);
//              Log.d("LSD", "lowAlpha: " + eegPower.lowAlpha);
//              Log.d("LSD", "highBeta: " + eegPower.highBeta);
//              Log.d("LSD", "lowBeta: " + eegPower.lowBeta);
//              Log.d("LSD", "lowGamma: " + eegPower.lowGamma);
//              Log.d("LSD", "midGamma: " + eegPower.midGamma);
//              Log.d("LSD", "delta: " + eegPower.delta);
//              Log.d("LSD", "theta: " + eegPower.theta);

                break;
            case TGDevice.MSG_STATE_CHANGE:

                // actual value of the message is determined by msg.arg1
                switch (msg.arg1) {
                case TGDevice.STATE_IDLE:
                    break;
                case TGDevice.STATE_CONNECTING:
                    meditation.append("Connecting...\n");
                    break;
                case TGDevice.STATE_CONNECTED:
                    meditation.append("Connected.\n");
                    device.start();
                    break;
                case TGDevice.STATE_NOT_FOUND:
                    meditation.append("Could not connect any of the paired BT devices.  Turn them on and try again.\n");
                    break;
                case TGDevice.STATE_ERR_NO_DEVICE:
                    meditation.append("No Bluetooth devices paired.  Pair your device and try again.\n");
                    break;
                case TGDevice.STATE_ERR_BT_OFF:
                    meditation.append("Bluetooth is off.  Turn on Bluetooth and try again.");
                    break;

                case TGDevice.STATE_DISCONNECTED:
                    meditation.append("Disconnected.\n");
                } /* end switch on msg.arg1 */

                break;

            case TGDevice.MSG_POOR_SIGNAL:
                //meditation.append("PoorSignal: " + msg.arg1 + "\n");
                break;

            case TGDevice.MSG_HEART_RATE:
                meditation.append("Heart rate: " + msg.arg1 + "\n");
                break;

            case TGDevice.MSG_RAW_DATA:
                /* Handle raw EEG/EKG data here */
                //tv.append("RAW EEG: " + msg.arg1); Note: commented out as trying to get the exact figs (gamma etc)
                break;

            case TGDevice.MSG_ATTENTION:
                //meditation.append("Attention: " + msg.arg1 + "\n");

                break;

            case TGDevice.MSG_MEDITATION:
                meditation.setText("Meditation: " + msg.arg1 + "\n");

                if(msg.arg1<=35){

                    //if mediation level is low it turns red
                    meditation.setBackgroundColor(Color.RED);

                }else if((msg.arg1<=70)&&(msg.arg1>=35)){
                      meditation.setBackgroundColor(Color.YELLOW);
                    }else{

                        meditation.setBackgroundColor(Color.GREEN);
                    }

                break;

            case TGDevice.MSG_BLINK:
                meditation.append("Blink: " + msg.arg1 + "\n");
                break;

            default:
                break;

            } /* end switch on msg.what */

            //sv.fullScroll(View.FOCUS_DOWN); May need to use this again if the scroll view is needed!

        } /* end handleMessage() */

    }; /* end Handler */

1 个答案:

答案 0 :(得分:0)

System.currentTimeMillis()

为系统时钟设置的系统时间为unix时间戳