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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:00:25+00:00 2026-06-14T03:00:25+00:00

I am new to android. i develop an application in which i calculate longitude

  • 0

I am new to android. i develop an application in which i calculate longitude & latitude of my current location and updating date & time at particular interval of time using handler for it & it map the location on Google map by getting data from this application, this application works accurately with updates but one problem is that this application is not working when mobile phone is locked.

  1. I want to run this application in background & it keep running until & unless then mobile phone is switched off.
    This application also start giving update when i reopen application after going back from this application.
  2. I want to display that date & time that is last updated. not restart application & not update date & time from current opening time. it continuously working in background & display the activity that is working in background.

Please help…
I’ll be very thankful

My code of main activity is here…

package com.ETrack;

public class ETrackActivity extends Activity {

public void acquire()

    {           final String TAG = null;
                PowerManager pm = (PowerManager)getApplicationContext().getSystemService(
                getApplicationContext().POWER_SERVICE);
                WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
                wl.acquire();
                wl.release();
    }


    private static final List<? extends NameValuePair> nameValuePairs = null;


    /** Called when the activity is first created. */
     static TelephonyManager tm;


     TextView GPS_Long_txtbx;
     TextView GPS_Lat_txtbx;
     static TextView last_update_time_txtbx;
     TextView onfig_txtbx;
     static String pswd_auth= "13579",  server_host="helpdesk.cispl.com";
     static String interval = "120";
     String Saveinterval = "interval.txt";
     String FILENAME3 = "savetime";
     String Savetime = "savetime.txt";

    Handler h = new Handler();
    Runnable run = new Runnable()

    {

        @Override
        public void run() {

            MyLocation loc = new MyLocation(getBaseContext());
            TextView longitude_view = (TextView) findViewById(R.id.GPS_Long_txta);
                   ((TextView) longitude_view)
                    .setText(" " + String.valueOf(loc.gps_lon));
            TextView latitude_view = (TextView) findViewById(R.id.GPS_Lat_txta);
            ((TextView) latitude_view).setText("  " + String.valueOf(loc.gps_lat));
            long delaytime =(record * 1000);
            last_update_time_txtbx = (TextView) findViewById(R.id.last_update_time_txt);
            last_update_time_txtbx.setText("  " + String.valueOf(java.text.DateFormat.getDateTimeInstance()
            .format(Calendar.getInstance().getTime())));
            tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            String response = CallWebService(tm.getDeviceId(), loc.gps_lon, loc.gps_lat);
            h.postDelayed(this, delaytime);

        }
    };



    public void Saveinterval(String Saveinterval) {
        try {
            File dir = getFilesDir();
            File file = new File(dir, Saveinterval);
            if (file.exists())
                file.delete();
            FileOutputStream fos = openFileOutput(Saveinterval,
                    Context.MODE_PRIVATE);
            fos.write(Saveinterval.getBytes());
            fos.close();
        } catch (Exception ex) {
            ex.getMessage();
        }
    }

    public int RestoreRecord0() 
    {
        try
        {

            File dir = getFilesDir();
            File file = new File(dir, Saveinterval);
            if (!file.exists()) {
                return Integer.parseInt(interval);
            }

            FileInputStream fileIS = new FileInputStream(file);
            BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
            String readString = new String();
            String data = " ";

            // just reading each line and pass it on the debugger

            while ((readString = buf.readLine()) != null) 
            {
                data += readString;
            }

            return Integer.parseInt(data);
        }

        catch (Exception ex) {
            ex.getMessage();
        }

        return Integer.parseInt(interval);
    }

   int record = RestoreRecord0();
   private static int activities = 0;

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




        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
        tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);


        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

        last_update_time_txtbx = (TextView) findViewById(R.id.last_update_time_txt);
        last_update_time_txtbx.setText(" "+ String.valueOf(java.text.DateFormat.getDateTimeInstance()
              .format(Calendar.getInstance().getTime())));  



        MyLocation loc = new MyLocation(this.getApplicationContext());
        TextView longitude_view = (TextView)findViewById(R.id.GPS_Long_txta);
        ((TextView) longitude_view).setText(" "+String.valueOf(loc.gps_lon));
        TextView latitude_view = (TextView)findViewById(R.id.GPS_Lat_txta);
        ((TextView) latitude_view).setText(" "+String.valueOf(loc.gps_lat));



        //refresh_location(GPS_Long_txtbx,GPS_lat_txtbx);


                final Button btnSkip = (Button) findViewById(R.id.btnRegister);
                // btnSkip.setTypeface(face);
                btnSkip.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        // Perform action on click EditText et


                        Intent i = new Intent(ETrackActivity.this, Configuration.class);                        
                        //i.putExtra("Skip", "true");
                        // i.putExtra("Location", txtEmail.getText());
                        startActivity(i);
                        }
                });


    //      last_update_time_txtbx = (TextView)findViewById(R.id.last_update_time_txt);
   //       last_update_time_txtbx.setText(" "+ String.valueOf(java.text.DateFormat.getDateTimeInstance()
//          .format(Calendar.getInstance().getTime())));



                // in this response variable it contains  
                String response = CallWebService(tm.getDeviceId(), loc.gps_lon, loc.gps_lat);


                long delaytime =(record * 1000);
                h.postDelayed(run, delaytime);


                }



  //   public void refresh_location(View longitude_view, View latitude_view, View last_update_time_txtbx)
     public void refresh_location(View longitude_view, View latitude_view)

    {

        longitude_view = (TextView)findViewById(R.id.GPS_Long_txta);
        ((TextView) longitude_view).setText(" "+String.valueOf(LocationService.GPS_Long));
        latitude_view = (TextView)findViewById(R.id.GPS_Lat_txta);
        ((TextView) latitude_view).setText(" "+String.valueOf(LocationService.GPS_Lat));
//      last_update_time_txtbx = (TextView)findViewById(R.id.last_update_time_txt);
//      ((TextView) last_update_time_txtbx).setText(""+String.valueOf(java.text.DateFormat.getDateTimeInstance()
//      .format(Calendar.getInstance().getTime())));

    }


    public void onNothingSelected(AdapterView<?> arg0) {

    }

        public void onClick(View view)
    {
        startActivity(new Intent(ETrackActivity.this,Configuration.class));

    }

        public String CallWebService(String imei, double longt, double lat) {
        String response = new String();
        String str = new String();

        try {

            String url = "http://helpdesk.cispl.com/etracking/track.php?imei="+imei+"&gps_lat="+ Double.toString(lat) +"&gps_lon="+Double.toString(longt);
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            URI webservice = new URI(url);
            request.setURI(webservice);
            HttpResponse httpResponse = client.execute(request);
            HttpEntity responseEntity = httpResponse.getEntity();    

             if (responseEntity != null) {
                    response = EntityUtils.toString(responseEntity);
                }           
            } catch (Exception e1){
                e1.printStackTrace();
            }

            return response;
        }


} 

please give me solution…..

  • 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-14T03:00:27+00:00Added an answer on June 14, 2026 at 3:00 am

    To run the application in background you need to use Service

    Tutorials on using services: here and here and this

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

Sidebar

Related Questions

I am new to android and I need to develop an application which stores
I am new to Android. I am trying to develop an Alarm Application, which
I am a new android developer. Currently I am working on an application which
I am trying to develop an Android based application, which can play video from
I'm new to android application development. I tried to develop an android server client
I new in the android developing. I want to develop simple application that will
I am trying to develop an android application which connect to SUP2.1.1. I am
I am new to android. I am trying to develop android helloworld application as
Here i develop one android application from which i want to share some text,picture
I'm new to Phonegap and I want to develop a Phonegap application for Android..

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.