2016-08-26 8 views
0

私はcountDownでAudioRecordからvalを取得しようとしましたが、Activityで余分なリストを取得したときに同じ値が含まれています(AudioRecordが、 。私を助けてください!。前もって感謝します。 注:私は45 * 1000および100CountDownTimerのアンドロイドputParcelableArrayListが返されたリストに同じ値を返しました

// Class of CountDownTimer 
dataValues = new ArrayList<Data>(); 
(MenuActivity)context).runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      new CountDownTimer(millis, intervalInMillis){ 
       @Override 
       public void onTick(long millisUntilFinished) { 
         firstValues.add(val); // val from AudioRecord 
        if (firstValues.size() >=10){ 
         firstValues.remove(0); 
         data.setValue(avgFromIntList(firstValues)); 
         data.setTime(new Date().getTime()); 
         dataValues.add(data); 

        } 
       } 

       @Override 
       public void onFinish() { 
        Bundle extras = new Bundle(); 

        extras.putLong("idSession", session.getId()); 
        extras.putParcelableArrayList("values",dataValues); 

        Intent toPast = new Intent(context, SessionPastActivity.class); 
        toPast.putExtras(extras); 
        context.startActivity(toPast); 

       } 
      }.start(); 
     } 
    }); 


// Model class that implement Parcelable 

パブリッククラスデータが{

private Integer value; 
private Long time; 

public Data(Integer value, Long time) { 
    this.value = value; 
    this.time = time; 
} 

public Data() { 
} 



public Integer getValue() { 
    return value; 
} 

public void setValue(Integer value) { 
    this.value = value; 
} 

public Long getTime() { 
    return time; 
} 

public void setTime(Long time) { 
    this.time = time; 
} 



@Override 
public String toString() { 
    return "Data{" + 
      ", value=" + value + 
      ", time=" + time + 
      '}'; 
} 

@Override 
public int describeContents() { 
    return 0; 
} 

@Override 
public void writeToParcel(Parcel dest, int flags) { 

    dest.writeInt(value); 
    dest.writeLong(time); 

    Log.e("inWrite", toString()); 
} 

// this is used to regenerate your object. All Parcelables must have a CREATOR that implements these two methods 
public static final Parcelable.Creator<Data> CREATOR = new Parcelable.Creator<Data>() { 
    public Data createFromParcel(Parcel in) { 
     return new Data(in); 
    } 

    public Data[] newArray(int size) { 
     return new Data[size]; 
    } 
}; 

// example constructor that takes a Parcel and gives you an object populated with it's values 
private Data(Parcel in) { 

    value = in.readInt(); 
    time = in.readLong(); 

    Log.e("inREAD", toString()); 
} 

//アクティビティクラス

のArrayList values_amplitude = getIntent()getExtras Parcelableを実装を通過カウントダウンを呼び出します().getParcelableArrayList( "values");

+0

のために働くことを願っていますしてみてください(http://stackoverflow.com/help/mcve)[検証可能な例、完全な、最小]を作成してください。 –

答えて

0

この

Bundle bundle=getIntent.getExtra(); 

    if(bundle != null){ 
    ArrayList<Data> values_amplitude = (ArrayList<Data>).getParcelable("values"); 
    } else {} 

が、それはあなた

+0

は動作しません。このエラーが発生します。期待されるキー値Parcelableですが、値はjava.util.ArrayListでした。デフォルト値が返されました。 java.lang.ClassCastException:java.util.ArrayListをandroid.os.Parcelableにキャストすることはできません。 –

+0

passこのような値は、\ Intent toPast = new Intent(context、SessionPastActivity.class)となります。toPast.putExtra( "idSession"、session.getId());toPast .putExtra( "values"、dataValues); context.startActivity(toPast); –

関連する問題