简体   繁体   中英

Parse.com - Parsing the value of a long instead of the name/title

I'm attempting to send the value of a long (in this case the long mStartTX) however each time I attempt to do so the title/name of the long (mStartTX) appears in my data browser instead of the data the long represents (total bytes of data used since the app launched)

How can this be corrected so the value the long represents appears in parse.com? I'm sure this is very simple. I simply cannot seem to send the data I need using the method below:

   testObject.put("time", Long.valueOf(mStartTX));

FULL SOURCE:

public class ParseStarterProjectActivity extends Activity {
TextView textSsid, textSpeed, textRssi;

public Handler mHandler = new Handler();
public long mStartRX = 0;
public long mStartTX = 0;


/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.parser);
textSsid = (TextView) findViewById(R.id.Ssid);
textSpeed = (TextView) findViewById(R.id.Speed);
textRssi = (TextView) findViewById(R.id.Rssi);
Long.toString(mStartTX);
ParseAnalytics.trackAppOpened(getIntent());
ParseObject testObject = new ParseObject("TestObject");
testObject.put("time", Long.valueOf(mStartTX));
testObject.saveInBackground();


mStartRX = TrafficStats.getTotalRxBytes();
mStartTX = TrafficStats.getTotalTxBytes();
if (mStartRX == TrafficStats.UNSUPPORTED || mStartTX == TrafficStats.UNSUPPORTED)     AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Uh Oh!");
alert.setMessage("Your device does not support traffic stat monitoring.");
alert.show();
} else {
mHandler.postDelayed(mRunnable, 1000);
}
}
private final Runnable mRunnable = new Runnable() {
public void run() {
TextView RX = (TextView)findViewById(R.id.RX);
TextView TX = (TextView)findViewById(R.id.TX);
long rxBytes = TrafficStats.getTotalRxBytes()- mStartRX;
RX.setText(Long.toString(rxBytes));
long txBytes = TrafficStats.getTotalTxBytes()- mStartTX;
TX.setText(Long.toString(txBytes));
mHandler.postDelayed(mRunnable, 1000);

There's no wonder, "mStartTX" is a String literal, and mStartTX is a variable of type long . Use mStartTX without quotes, and in case the method doesn't accept long as a parameter, use Long.toString(mStartTX) and then parse it using Long.valueOf(mStartTXStr) . Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM