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

  • Home
  • SEARCH
  • 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 6388531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:17:24+00:00 2026-05-25T03:17:24+00:00

I am trying to create an app that will send some data to a

  • 0

I am trying to create an app that will send some data to a webserver after x mins. I was told that an alarm manager would be the best solution and just call the same alarm function with an extra x mins inside the alarm so that it will constantly send the data even in the background.

However I have only seen alarms open intents within the project. Does that mean it will switch to the new intent after x mins or will everything work in the background?

The background data should be sent without having to switch between intents so I would prefer it to just call a function inside one of my activities. How should I go about doing this?

Here is the function I would like to call every x mins.

Thanks

public class updateloc extends AsyncTask<Void, Void, Void> {

    protected void onPostExecute(String response) {
        if (response != null) {
            // check if this does anything later
        }
        progressDialog.dismiss();
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog = ProgressDialog.show(ImTracking.this, "",
                "Updating Data...");
    }

    @Override
    protected Void doInBackground(Void... arg0) {
        SharedPreferences prefs = getSharedPreferences("Settings", 0);
        final String id = prefs.getString("ID", "");
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httpost = new HttpPost(
                "http://iphone-radar.com/gps/gps_locations");

        JSONObject holder = new JSONObject();

        try {
            holder.put("id", id);
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
            Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            String bestProvider = locationManager.getBestProvider(criteria,
                    false);
            LocationListener loc_listener = new LocationListener() {

                @Override
                public void onStatusChanged(String provider, int status,
                        Bundle extras) {
                }
            };
            try {
                Looper.prepare();
                locationManager.requestLocationUpdates(bestProvider, 0, 0,
                        loc_listener);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Location location = locationManager
                    .getLastKnownLocation(bestProvider);
            Calendar c = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat(
                    "hh:mmaa MM/dd/yyyy");
            holder.put("time", sdf.format(c.getTime()));
            holder.put("time_since_epoch", System.currentTimeMillis());
            try {
                holder.put("lat", location.getLatitude());
                holder.put("lon", location.getLongitude());
            } catch (NullPointerException e) {
                try {
                    holder.put("lat", -1.0);
                    holder.put("lon", -1.0);
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
            }

            StringEntity se = new StringEntity(holder.toString());
            httpost.setEntity(se);
            httpost.setHeader("Accept", "application/json");
            httpost.setHeader("Content-type", "application/json");

            ResponseHandler responseHandler = new BasicResponseHandler();
            String response = httpclient.execute(httpost, responseHandler);
            org.json.JSONObject obj;

            obj = new org.json.JSONObject(response);

        } catch (JSONException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        progressDialog.dismiss();
        return null;
    }
}
  • 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-05-25T03:17:25+00:00Added an answer on May 25, 2026 at 3:17 am

    If you want this to work in the background, you need to create a service. Services can be started using intents, so you can start your service using the AlarmManager. Have a look at IntentService, you just need to move what you are currently doing in your AsyncTask in the servcie’s handleIntent() method.

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

Sidebar

Related Questions

I'm trying to create a C# form app that will allow me to use
Trying to create my first iPhone app that would play back audio. When I
I'm trying to create a simple Java app that uses JNI to call some
I am trying to create an app that will display articles from an online
I am trying to create an app that will allow me to stream video
I'm trying to create a cron job that will send a weekly newsletter. I
I'm trying to create a windows form app that will be able to handle
I'm trying to create coloumns of text for a C# app that will be
I'm trying to create an app that will help keep track of attendance information
I am trying to create an app that will help to find nearby places

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.