I am currently developing and App that calculates a few simple variables at the end of an activity and then uploads them to a server at the beginning of the next activity:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.fairwell);
setTimer();
}
@Override
public void onResume(){
super.onResume();
is_active = true;
Log.d(TAG, "onResume enter FA");
//Download Variable Ids start
int WeightId = postmeasurements.getStatisticId(postmeasurements.mHCAW);
int BFPId = postmeasurements.getStatisticId(postmeasurements.mHCABFP);
int HydId = postmeasurements.getStatisticId(postmeasurements.mHCAHyd);
int MuscMass = postmeasurements.getStatisticId(postmeasurements.mHCAMM);
//Download Variable Ids End
Log.w("ANTApp", "WeightId is: " + WeightId);
Log.w("ANTApp", "BFPId is: " + BFPId);
Log.w("ANTApp", "HydId is: " + HydId);
Log.w("ANTApp", "MuscMass is: " + MuscMass);
//Post Measurements to Server Start
postmeasurements.postScaleMeasurements(WeightId, PostMeasurements.Weight);
postmeasurements.postScaleMeasurements(BFPId, PostMeasurements.BFP);
postmeasurements.postScaleMeasurements(HydId, PostMeasurements.Hyd);
postmeasurements.postScaleMeasurements(MuscMass, PostMeasurements.MuscMass);
//Post Measurements to Server End
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100 / 112.0f;
getWindow().setAttributes(lp);
setTimer();
Log.d(TAG, "onResume exit FA");
}
The problem I am having here is that this causes a black screen between each activity that remains until all the measurements have been uploaded. Each downloading and uploading method is run on its own background thread using Httppost:
public void postScaleMeasurements(int StatId, double Value){
//int Id = 0;
String result = "";
//the serial data to send
final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("s", mDeviceId));
nameValuePairs.add(new BasicNameValuePair("statisticId", Integer.toString(StatId)));
nameValuePairs.add(new BasicNameValuePair("userId", Integer.toString(mHCAId)));
nameValuePairs.add(new BasicNameValuePair("statisticValue", Double.toString(Value)));
InputStream is = null;
Thread PostScaleData = new Thread(){
public void run(){
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://www.website.com/app/postStatisticValue.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
streamresponse = entity.getContent();
}catch(Exception e){
Log.e(TAG, "Error in http connection (verifytablet) "+e.toString());
}
}
};
PostScaleData.start();
try {
PostScaleData.join(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
and I am still receiving a black screen of approximatly 1 - 4 seconds. What I really want is for the layout drawing process to finish before any measurements are uploaded.
Thank you all in advance for your amazing support.