Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get the current activity output and set it to display?
    text
    copied!<p>I have completed one android application for taxi booking. In this i designed two screens. one is named as job started screen and anther one is named as job completion screen. In job started screen i have wrote two conditions using if else statement. In if condition i set minimum fare as 100 for 4 kilometers. if toatalkm goes above minDist means i go for else condition and here i make some calculations for every km add 10 rupee with that minimum fare and for waiting time. like below i shown.</p> <pre><code> if (totalKm&lt;Contsants.minDist) { jcWaitingFare.setText("0"); float totalfare=Contsants.minFare; jcTotalFare.setText(String.format("%.2f",(totalfare))); Contsants.jobTotalKm= totalKm; Contsants.jobTotalFare=totalfare; } else { jcWaitingFare.setText(Integer.toString((Contsants.cont_WaitingTimeInSec/60)*1)); float totalfare= Contsants.minFare+ ((totalKm-Contsants.minDist) *Contsants.rupeeKm) +(Contsants.cont_WaitingTimeInSec/60)*1; jcTotalFare.setText(String.format("%.2f",(totalfare))); Contsants.jobTotalKm= totalKm; Contsants.jobTotalFare=totalfare; } </code></pre> <p>I want to display the current fare details into the job completed screen. I dont know how to get the current fare details from the above statement and set it to the job completion activity. today only tested my app. then only i came to know that application hangs up on the job started screen. </p> <p>below is my screen. here the calculation is not displayed properly. when click on the finish button it moves to job completed activity. in this activity we designed to see the total fare and waiting time. how to get the current details from this screen and set it to the job completed screen.</p> <p><img src="https://i.stack.imgur.com/DmjMr.png" alt="enter image description here"> job completed screen class:</p> <pre><code>private TextView jcJobNo; private TextView jcStartTime; private TextView jcEndTime; public TextView jcTotalKms; public TextView jcTotalFare; public TextView jcWaitingFare; private Button btn_JobCompleted; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_jobcompletedscreen); tcpSocket.setmMessageListener(this); StateManager.DeviceStatus=StateManager.free; StateManager.JobStatus=StateManager.jobstatus_completed; tcpSocket.SendMessage(FramePacket.FrameJobStatusCmd(Contsants.Jobno, StateManager.JobStatus)); jcJobNo=(TextView)findViewById(R.id.tv_jCjobno); jcStartTime= (TextView)findViewById(R.id.tv_JCStartTime); jcEndTime= (TextView)findViewById(R.id.tv_JCEndTime); jcTotalKms= (TextView)findViewById(R.id.tv_JCTotalKMs); jcTotalFare= (TextView)findViewById(R.id.tv_JCTotalFare); btn_JobCompleted = (Button)findViewById(R.id.btn_jcFinsh); btn_JobCompleted.setOnClickListener(onclicklistner); jcWaitingFare=(TextView)findViewById(R.id.tv_JCWaitingFare); jcJobNo.setText(Contsants.Jobno); jcStartTime.setText(Contsants.jobStartTime); jcEndTime.setText(Contsants.jobEndTime); // total distance finding here float totalKm = Contsants.jobEndKm-Contsants.jobStartKm ; jcTotalKms.setText(String.format("%.2f",totalKm)); //jcTotalKms.setText(Float.toString((float) (totalKm/16.0))); //finding total fare here //int value=100; if (totalKm&lt;Contsants.minDist) { jcWaitingFare.setText("0"); float totalfare=Contsants.minFare; jcTotalFare.setText(String.format("%.2f",(totalfare))); Contsants.jobTotalKm= totalKm; Contsants.jobTotalFare=totalfare; } else { jcWaitingFare.setText(Integer.toString((Contsants.cont_WaitingTimeInSec/60)*1)); float totalfare= Contsants.minFare+ ((totalKm-Contsants.minDist) *Contsants.rupeeKm) +(Contsants.cont_WaitingTimeInSec/60)*1; jcTotalFare.setText(String.format("%.2f",(totalfare))); Contsants.jobTotalKm= totalKm; Contsants.jobTotalFare=totalfare; } } private OnClickListener onclicklistner = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.btn_jcFinsh: tcpSocket.SendMessage(FramePacket.FrameJobFarecmd(Contsants.jobTotalKm, Contsants.jobTotalFare, Contsants.Jobno, Contsants.jobTotalwaitingTime,Contsants.jobOncallDistacnce)); Contsants.cont_WaitingTimeInSec=0; Contsants.Jobno=""; Contsants.JobCustomerName=""; Contsants.JobCustomerNo=""; Contsants.JobFromAdd=""; Contsants.JobToAdd=""; Contsants.JobAdditionalInfo=""; Contsants.JobpickupTime=""; Contsants.JobString=""; Contsants.VehicleEndOdometer=0.0F; Contsants.VehicleStartOdometer=0.0F; Contsants.jobDistance=0.0F; Contsants.jobEndKm=0.0F; Contsants.jobStartKm=0.0F; Contsants.jobOncallDistacnce=0.0F; Contsants.jobEndTime=""; Contsants.jobStartTime=""; Contsants.JobString=""; Contsants.jobTotalwaitingTime = ""; Contsants.jobTotalFare= 0.0F; Contsants.jobTotalKm= 0.0F; Intent i = new Intent(getApplicationContext(),FreeScreen.class); startActivity(i); break; } } }; @Override public void onBackPressed() { // do nothing. super.onBackPressed(); finish(); } @Override public void messageReceived(String message) { // TODO Auto-generated method stub } } </code></pre> <p>job started screen class:</p> <pre><code>TextView tv_JobNo; static TextView tv_JobKm; static TextView tv_speed; static TextView tv_JobwaitngTime; TextView tvjobstartedtime; Button btn_jobFinsh; Button btn_msg; ImageButton navig; boolean _ThreadFlag=false; boolean _ResumeThread=false; private Window w; Thread t=null; String jobno; String tag="Jobstartscreen"; private static MyThread sThread; static TextView tv_Fare; private TextView jcTotalFare; private TextView jcWaitingFare; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.jobstartedscreen); if (savedInstanceState==null){ Contsants.VehicleStartOdometer=0.0F; sThread=new MyThread(mHandler); sThread.start(); } tcpSocket.setmMessageListener(this); tv_JobNo =(TextView)findViewById(R.id.tvJobid); Bundle bundle = getIntent().getExtras(); jobno= bundle.get("Jobno").toString(); tv_JobNo.setText(jobno); tv_JobKm =(TextView)findViewById(R.id.tvjobKm); tv_JobwaitngTime =(TextView)findViewById(R.id.tvjobWaittime); tv_speed=(TextView)findViewById(R.id.speed); tv_Fare=(TextView)findViewById(R.id.tv_fare); tv_JobwaitngTime.setText("Waiting Time : 0:0"); //update the Km every 1 sec Log.d(tag, "On created "+_ResumeThread); tvjobstartedtime=(TextView)findViewById(R.id.tv_jobStarttime); tvjobstartedtime.setText("Start Time :"+Contsants.jobStartTime); btn_jobFinsh= (Button)findViewById(R.id.btn_jobFinsh); btn_jobFinsh.setOnClickListener(onClickListener); btn_msg= (Button)findViewById(R.id.btn_msg); btn_msg.setOnClickListener(onClickListener); StateManager.DeviceStatus=StateManager.hired; // TODO Auto-generated method stub } @Override public void onStart() { super.onStart(); } @Override public void onResume() { super.onResume(); w = this.getWindow(); w.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD); w.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); w.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON); Log.d("job start on resume",_ThreadFlag+" "+_ResumeThread); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState){ super.onRestoreInstanceState(savedInstanceState); if (sThread.isAlive()){ sThread.setHandler(mHandler); } } @Override protected void onDestroy(){ super.onDestroy(); if (sThread.isAlive()){ sThread.setHandler(null); } sThread.setHandler(null); } boolean _Paused=false; @Override public void onPause() { super.onPause(); _Paused=true; } @Override public void onBackPressed() { // do nothing. } private OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(final View v) { switch(v.getId()){ case R.id.btn_jobFinsh: //DO something _ThreadFlag=true; StateManager.JobStatus=StateManager.jobstatus_dropped; tcpSocket.SendMessage(FramePacket.FrameJobStatusCmd(Contsants.Jobno,StateManager.JobStatus)); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy HH:mm"); String currentDateandTime = sdf.format(new Date()); Contsants.jobEndTime=currentDateandTime; Contsants.jobEndKm =gpsdataElements.Distance; Intent i = new Intent(getApplicationContext(),JobCompletionScreen.class); startActivity(i); sThread.setHandler(null); finish(); break; case R.id.btn_msg: /*Intent iNAV = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=12.920629,77.610643&amp;daddr=12.990346, 77.589521") ); startActivity(iNAV);*/ Intent imsg = new Intent(getApplicationContext(),MessageList.class); startActivity(imsg); break; } } }; static Handler mHandler =new Handler(){ @Override public void handleMessage(Message message){ //update UI Bundle b = message.getData(); float odometer = b.getFloat("My Odometer"); String Fare = b.getString("Fare"); int waiting =b.getInt("waiting Time"); double speedVal= b.getDouble("SpeedValue"); tv_speed.setText(String.format("%.2f",speedVal)+" Km/hr"); tv_JobKm.setText(String.format("%.2f",odometer)+" Km"); tv_Fare.setText(Fare); tv_JobwaitngTime.setText(Integer.toString((waiting / 60)) +":"+ Integer.toString((waiting% 60))); Contsants.jobTotalwaitingTime=Integer.toString((waiting / 60)) +":"+ Integer.toString((waiting% 60)); } }; private class MyThread extends Thread{ private Handler mHandler; public MyThread(Handler handler){ super(); mHandler=handler; } @Override public void run(){ //some long operation if (mHandler!=null) mHandler.sendEmptyMessage(0); _ResumeThread=true; while(!_ThreadFlag) { try { Thread.sleep(1000); Message msg = new Message(); Bundle b = new Bundle(); b.putFloat("My Odometer", (float) (gpsdataElements.Distance-Contsants.jobStartKm)); if(gpsdataElements.Speed&lt;1) { Contsants.cont_WaitingTimeInSec++; } float totalKm = Contsants.jobEndKm-Contsants.jobStartKm ; if (totalKm&lt;Contsants.minDist) { //jcWaitingFare.setText("0"); float totalfare=Contsants.minFare; b.putString("Fare", String.format("%.2f",(totalfare))); } else { float totalfare= Contsants.minFare+ ((totalKm-Contsants.minDist) *Contsants.rupeeKm) +(Contsants.cont_WaitingTimeInSec/60)*1; b.putString("Fare", String.format("%.2f",(totalfare))); } b.putInt("waiting Time", Contsants.cont_WaitingTimeInSec); b.putDouble("SpeedValue", gpsdataElements.Speed*1.852); // tv_JobwaitngTime.setText("Waiting Time : "+Integer.toString((Contsants.cont_WaitingTimeInSec / 60)) +":"+ Integer.toString((Contsants.cont_WaitingTimeInSec % 60))); //send message to the handler with the current message handler msg.setData(b); // send message to the handler with the current message handler mHandler.sendMessage(msg); } catch (Exception e) { Log.v("Error", e.toString()); } } } public void setHandler(Handler handler){ mHandler=handler; } } @Override public void messageReceived(String message) { // TODO Auto-generated method stub //Toast.makeText(getApplicationContext(), "Job StartScreem : Recived data :"+message, Toast.LENGTH_LONG).show(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload