Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:10:55+00:00 2026-06-15T23:10:55+00:00

I create an gpsservice, a main activity with two buttons and a list activity.

  • 0

I create an gpsservice, a main activity with two buttons and a list activity. I’d like to get the gpsservie data when the gps data is obtained, so I create a gps receiver in the main activity to get the data. When I click the button in the main activity, it turns to the list activity. I’d like to transfer the obtained data to the list activity by using intent() when the button is clicked. the problem is that when I click the button, there is nothing shown in the listview.

the key codes of GPS service :

LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            additem(location);
            addgeo(location);
            //String latLongString = "Lat:" + location.getLatitude() + "\nLong:" + location.getLongitude();
            Intent intent= new Intent("com.example.geotask.gpsdata");
            intent.putIntegerArrayListExtra("lat", (ArrayList<Integer>) lat);
            intent.putIntegerArrayListExtra("lon", (ArrayList<Integer>) lon);
            intent.putStringArrayListExtra("data", (ArrayList<String>) position);
            //intent.putExtra("data", latLongString);
            sendBroadcast(intent);    }

the main activity code:

public class MainActivity extends Activity {

    public  ArrayList<String> position1 = new ArrayList<String>(); 
    public  ArrayList<Long> time=new ArrayList<Long>();
    public  ArrayList<Integer> lat1= new ArrayList<Integer>(); 
    public  ArrayList<Integer> lon1= new ArrayList<Integer>(); 
    private BroadcastReceiver gpsreceiver;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        IntentFilter intentFilter=new IntentFilter("com.example.geotask.gpsdata");
        gpsreceiver=new BroadcastReceiver()
        {
            @Override 
            public void onReceive(Context context, Intent intent)
            {
             ArrayList<String> position1=intent.getStringArrayListExtra("data");
             ArrayList<Integer> lat1=intent.getIntegerArrayListExtra("lat");
            ArrayList<Integer> lon1=intent.getIntegerArrayListExtra("lon");
            }

        };
        this.registerReceiver(gpsreceiver, intentFilter);

        final Button listbutton=(Button) findViewById(R.id.button2);
        listbutton.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
                Intent intent =new Intent();
                intent.setClass(MainActivity.this, list.class);
                intent.putStringArrayListExtra("data", (ArrayList<String>) position1);
                startActivity(intent);

            }
        });
        }

the list activity:

public class list extends Activity{ 
    static ArrayList<listdetails> details = new ArrayList<listdetails>();
   // private BroadcastReceiver gpsreceiver;

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.list); 
        ListView listView; 
        listView = (ListView)findViewById(R.id.listView1);
        Intent intent=getIntent();
        List<String> ex=intent.getStringArrayListExtra("data");
        customlist Adapter = new customlist(details, this);
        listView.setAdapter(Adapter);
        listdetails Detail = new listdetails();
            for(int i=0;i<ex.size();i++)
            {
                Detail.setIcon(R.drawable.ic_launcher);
                Detail.setPlace(ex.get(i));
                Detail.setTime("2012.12.2");
                details.add(Detail);

            }

            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:10:57+00:00Added an answer on June 15, 2026 at 11:10 pm

    You are duplicating your variables in onReceive(). This means that the ArrayList variables get destroyed once onReceive() completes. Your onReceive() should look like:

            @Override 
            public void onReceive(Context context, Intent intent)
            {
              position1=intent.getStringArrayListExtra("data");
              lat1=intent.getIntegerArrayListExtra("lat");
             lon1=intent.getIntegerArrayListExtra("lon");
            }
    

    This ensures that you are now modifying the global ArrayLists. Also, you may need to declare the global ArrayLists as final since Java might treat your new BroadCastReceiver as an anonymous inner class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Create a GPSservice for my app and I would like to get the
I have used SimpleCursorAdapter for display the data into a list in my activity
Create a new appdomain, setup the assemblyResolve handler and you always get an exception
I need to create two methods as follows: Retrieve all changesets in TFS. Retrieve
I'm making a plugin that triggers on the create message of a custom activity
This is my sistuation A1 = Splash Screen Activity A2 = Main Activity A3
I'm having a problem with binding service to an activity. I get playing_service==null. I
CREATE TABLE `tbl_atn` ( `atn_id` int(15) NOT NULL AUTO_INCREMENT, `eng_id` int(15) DEFAULT NULL, `visit`
CREATE OR REPLACE FUNCTION layer2layerAttribute RETURN VARCHAR2 AS /** * This function properly joins
CREATE TABLE #TEMPTABLE ( requestTime datetime2, NoOfSessions integer ) INSERT INTO #TEMPTABLE select convert(nvarchar(16),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.