我尝试在countDown中从AudioRecord获取val但是当我在Activity中获得额外的列表时,包含相同的值(我已经检查过AudioRecord返回了不同的值)。请帮我!。提前致谢。 注意:我调用countDown传递45 * 1000和100
// 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
public class Data实现了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()。getParcelableArrayList(“values”);
答案 0 :(得分:0)
试试这个
Bundle bundle=getIntent.getExtra();
if(bundle != null){
ArrayList<Data> values_amplitude = (ArrayList<Data>).getParcelable("values");
} else {}
希望它对您有用