Reputation: 132
I have doing a file from the server, and my idea is to pass the filesizedownloaded to a class and on my progressbar class get value to update the progress bar; I have a function that passes a value to a class
this is how i try to pass the value
new updateValue(fileSizeDownloaded);
value gets stored here public class updateValue{ private long v_value;
public updateValue(long value) {
v_value = value;
}
public long getV_value() { return v_value; };
}
and from a different class I'm trying to get the value of getV_value but I keep getting an error; update(long) in update cannot be applied to 0
How can i get the value stored :/ all this is on mainactivity.java
updateValue value = new updateValue();
value.getV_value();
Upvotes: 1
Views: 32
Reputation: 1450
What you can do is create a new class and extend Application
public class yourcalss extends Application {
public long getValue() {
return value;
}
public void setValue(long value_e) {
value = value_e;
}
}
This is how you save the value
final yourcalss value = (yourcalss ) getApplicationContext();
value.setValue(fileSizeDownloaded);
and this is how you can access the value
final yourcalss val = (yourcalss ) getApplicationContext();
final Long v = val.getValue();
and manifiest
<application android:name="yourcalss
Upvotes: 1
Reputation: 123
You didn't set the initial value when creating an instance of updateValue
. Pass a value like this
long val = 1000; //can be any long value
updateValue value = new updateValue(val);
value.getValue();
Upvotes: 1