I need to send data from an activity to a persistently running GPS
service and I'm not certain how to do this. Below is the code from my
activity and service. ANY help is greatly appreciated.

//%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
//                                 THIS IS THE ACTIVITY
//%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%

@Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.tripinformation);


    Button button = (Button)findViewById(R.id.pickup_load);
    button.setOnClickListener(mPickupListener);
    button = (Button)findViewById(R.id.deliver_load);
    button.setOnClickListener(mDeliveryListener);
    button = (Button)findViewById(R.id.pickup_delivery);
    button.setOnClickListener(mPickupDeliveryListener);
    button = (Button)findViewById(R.id.railhead);
    button.setOnClickListener(mRailHeadListener);
    button = (Button)findViewById(R.id.warehouse);
    button.setOnClickListener(mWarehouseListener);
    button = (Button)findViewById(R.id.other);
    button.setOnClickListener(mOtherLocationListener);
    button = (Button)findViewById(R.id.gate);
    button.setOnClickListener(mGateListener);
    button = (Button)findViewById(R.id.terminal);
    button.setOnClickListener(mTerminalListener);
    button = (Button)findViewById(R.id.traffic);
    button.setOnClickListener(mTrafficListener);
    button = (Button)findViewById(R.id.onbreak);
    button.setOnClickListener(mBreakListener);
    button = (Button)findViewById(R.id.fueling);
    button.setOnClickListener(mFuelingListener);
    button = (Button)findViewById(R.id.closed);
    button.setOnClickListener(mDestinationClosedListener);
    button = (Button)findViewById(R.id.closed);
    button.setOnClickListener(mPaperworkListener);
    button = (Button)findViewById(R.id.paperwork);
    button.setOnClickListener(mEquipmentListener);
    button = (Button)findViewById(R.id.equipment);
    button.setOnClickListener(mOtherIssueListener);
    button = (Button)findViewById(R.id.other_issue);
    //Return to the LoginActivity
    button = (Button)findViewById(R.id.Back);
    button.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
                finish();
        }
    });
}

//%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
//                                                      Set the listeners
//          The data from these button presses need to be sent to the
main service
//%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&

private OnClickListener mPickupListener = new OnClickListener() {
    public void onClick(View v)
    {
        getStatus("Pickup");
    }
        };
  private OnClickListener mDeliveryListener = new OnClickListener() {
        public void onClick(View v)
    {
                getStatus("Delivery");
    }
  };
  private OnClickListener mPickupDeliveryListener = new
OnClickListener() {
    public void onClick(View v)
    {
        getStatus("Pickup/Delivery");
    }
};

        private OnClickListener mRailHeadListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Railhead");
                }
        };

        private OnClickListener mWarehouseListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Warehouse");
                }
        };
  private OnClickListener mOtherLocationListener = new
OnClickListener() {
    public void onClick(View v)
    {
        getStatus("OtherLocation");
    }
  };
        private OnClickListener mGateListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Gate");
                }
        };
        private OnClickListener mTerminalListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Terminal");
                }
        };
        private OnClickListener mTrafficListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Traffic");
                }
        };
        private OnClickListener mBreakListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Break");

                }
        };
        private OnClickListener mFuelingListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Fueling");
                }
        };
        private OnClickListener mDestinationClosedListener = new
OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("DestClosed");
                }
        };
        private OnClickListener mPaperworkListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Paperwork");
                }
        };
        private OnClickListener mEquipmentListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("Equipment");
                }
        };
        private OnClickListener mOtherIssueListener = new OnClickListener() {
                public void onClick(View v)
                {
                        getStatus("OtherIssue");
                }
        };



//%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%
%&
//                                                      I Want to pass 
TRIP_INFO to the Main Service
//%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
%
                public static String getStatus(String info){
                TRIP_INFO = info;
                return TRIP_INFO;
        }

}




//%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
//                        THIS IS THE PORTION OF THE SERVICE I WANT TO
UPDATE
//%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%%

public class MyLocationListener implements LocationListener {

public void onLocationChanged(Location loc) {
        if (loc != null) {
                boolean pointIsRecorded = true;
                try {

                                GregorianCalendar greg = new 
GregorianCalendar();
                                TimeZone tz = greg.getTimeZone();
                                int offset = 
tz.getOffset(System.currentTimeMillis());
                                greg.add(Calendar.SECOND, (offset/1000) * -1);
                                StringBuffer queryBuf = new StringBuffer();
                                queryBuf.append("INSERT INTO 
"+POINTS_TABLE_NAME+
                                                " 
(GMTTIMESTAMP,LATITUDE,LONGITUDE,TRIPINFO) VALUES (" +
                                                
"'"+timestampFormat.format(greg.getTime())+"',"+
                                                loc.getLatitude()+","+
                                                loc.getLongitude()+","+
                                                
TripInformationActivity.TRIP_INFO +");");   //This is the data i
need from the activity
                                Log.i(TAG, queryBuf.toString());
                                db = openOrCreateDatabase(DATABASE_NAME,
SQLiteDatabase.OPEN_READWRITE, null);
                                db.execSQL(queryBuf.toString());
                } catch (Exception e) {
                        Log.e(TAG, e.toString());
                } finally {
                        if (db.isOpen())
                                db.close();
                }

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to