0

I've been struggling with this for awhile and decided to ask fro some help. I've read the literature but still can't seem to make this code work for me. I'm using Fedor's code to try to return location and display it with my intent. I want the time/date and location to display in my next activity. The time/date is working fine I'm having trouble initiating the MyLocation class and passing that value to the intent. Any help or pointing to any other resources would be cool. Thanks.

Here's what I have I have so far.

package com.tree;

import java.util.Calendar;
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import com.tree.MyLocation.LocationResult;

    public class MainActivity extends Activity {

    @Override 
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    }

   LocationResult locationResult = new LocationResult(){
        @Override
        public void gotLocation(Location location){
            //Got the location!
        }
    };
    MyLocation myLocation = new MyLocation();
    myLocation.getLocation(this, locationResult);


    public void clockin (View view){
        Intent intent = new Intent (this, Mainmenu.class);
        String timedate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()) , locationResult;
        intent.putExtra("TIME_DATE", timedate);
        startActivity(intent);
    }
}

This is my first app

Community
  • 1
  • 1
3uccess
  • 13
  • 3

2 Answers2

0

Hi I think it should be something like this:

public class MainActivity extends Activity {

    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // get the location
        MyLocation myLocation = new MyLocation();
        myLocation.getLocation(this, locationResult);

    }

   LocationResult locationResult = new LocationResult(){
        @Override
        public void gotLocation(Location location){
            //Got the location! Then send the location and time...
            Intent intent = new Intent (this, Mainmenu.class);
            String timedate =       java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()) , locationResult;
            // set the time/date
            intent.putExtra("TIME_DATE", timedate);
            // set the location
            intent.putExtra("LOCATION_LAT", location.getLatitude());
            intent.putExtra("LOCATION_LONG", location.getLongitude());
            // start the new activity..
            startActivity(intent);
        }
    };



    public void clockin (View view){
        Intent intent = new Intent (this, Mainmenu.class);
        String timedate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime()) , locationResult;
        intent.putExtra("TIME_DATE", timedate);
        startActivity(intent);
    }
}

Please read the documentation for Location and Intent as I made this code from my head and I am not 100% sure of the methods used but it should give you a good start.

Cata
  • 11,133
  • 11
  • 65
  • 86
  • I tried the code and will try again thanks for the help man just now getting around to tweaking it to work thanks for the reply. – 3uccess Jul 11 '13 at 22:14
0

You can add it using a bundle

...
Bundle b = new Bundle();
...
b.putSerializable( "location", LocationObject ); //make sure Location class implement Serializable

intent.putExtras( b );

...
jeremyvillalobos
  • 1,795
  • 2
  • 19
  • 39
  • I apologize that it's taken me so long to check back with you guys. I've tried a bundle and it isn't working right. Right now I keep getting an error on mylocation.getLocation line saying it's looking for something can't figure out if it's the code or my java that's brokeded. – 3uccess Jul 11 '13 at 22:15