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 8782463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:33:56+00:00 2026-06-13T20:33:56+00:00

Could I write a thread in Android the Application class? This thread is running

  • 0

Could I write a thread in Android the Application class?
This thread is running every five minutes to post data to a webservice.

public class MyApplication  extends Application {
@Override
public void onCreate() {
    startUploadGPSTimer();
}

private void startUploadGPSTimer() {
    gpsTimerHandler.postDelayed(runnable, 5* 60 * 1000); // start Timer
}

private Handler gpsTimerHandler = new Handler();

private Runnable runnable = new Runnable() {
    public void run() {
        Map<String, String> params = new HashMap<String, String>();
        params.put("latitude", Global.CUR_LATITUDE);
        params.put("longitude", Global.CUR_LONGITUDE);
        WebServiceObj obj = new WebServiceObj("upload",
                WebServiceMethod.METHOD_UPLOAD_GPS,
                Utilly.getSoapParams(params));
        SoapService service = null;
        SoapObject result = null;
        service = new SoapService(obj.tag);
        result = service.LoadResult(obj);
        Log.i("post webservrce  ", result.toString());
        gpsTimerHandler.postDelayed(this, 5 * 60 * 1000);
    }
};

When my application enter background, this thread like do not running. Because of the data I post in thread Finally input to Database, and I can’t find it in db.

Why?

I write some log when do post data to webservice. and found the log be generated randomly.
Very strange

  • 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-13T20:33:57+00:00Added an answer on June 13, 2026 at 8:33 pm
    Intent photosIntent = new Intent(this, MyService.class);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,photosIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 5*60*1000,5*60*1000, pendingIntent);
    

    In MyService is a Service Class write your stuff in onstart to send request to webservices. This service will call for every 5minutes.

    Hope this helps.

    Thanks

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

Sidebar

Related Questions

Sure I could write this myself, but before I go reinventing the wheel is
I write this code in Main.java class but the program not run. Why? the
Could someone recommend good book on how to write thread safe containers? thanks
I'm trying to write an android application that has two main activities: login screen
Is there a piece of code I could write to be notified when a
If you have a C function which returns an integer, you could write a
i'm using DbSimple, but there is some code which i could write into another
How could i write word on the web, and save the content to a
How could you write a unittest in Python that would test that the output
How could I write code to get all the action names from a controller

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.