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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:23:57+00:00 2026-05-21T22:23:57+00:00

I have created one service and also added it in manifest. When I use

  • 0

I have created one service and also added it in manifest. When I use timer to call this service periodically and in timer I have used location manager to get location of user contin. But there is error like that:

05-11 11:57:17.574:
ERROR/AndroidRuntime(3305):
java.lang.RuntimeException: Can’t
create handler inside thread that has
not called Looper.prepare()

Tell me where is problem in my code.

code is here

package com.collabera.labs.sai;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class SimpleService extends Service {
    Timer mytimer;

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    Toast.makeText(this,"Service created ...", Toast.LENGTH_LONG).show();
    mytimer = new Timer();
    mytimer.schedule(new TimerTask() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            //getdata();
            LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            LocationListener mlocListener = new MyLocationListener();
            mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                    mlocListener);

        }
    },0,1000);

}

@Override
public void onDestroy() {
    super.onDestroy();
    Toast.makeText(this, "Service destroyed ...", Toast.LENGTH_LONG).show();
}
public void getdata()
{

}
public class MyLocationListener implements LocationListener {
    @Override
    public void onLocationChanged(Location loc) {
        loc.getLatitude();
        loc.getLongitude();
        String Text = "My current location is: " + "Latitude = "
                + loc.getLatitude() + "Longitude = " + loc.getLongitude();
        /*Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
                .show();*/
        Log.d("TAG", "Starting..");
    }

    @Override
    public void onProviderDisabled(String provider) {
        /*Toast.makeText(getApplicationContext(), "Gps Disabled",
                Toast.LENGTH_SHORT).show();*/
    }

    @Override
    public void onProviderEnabled(String provider) {
        /*Toast.makeText(getApplicationContext(), "Gps Enabled",
                Toast.LENGTH_SHORT).show();*/
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}/* End of Class MyLocationListener */
}
  • 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-21T22:23:57+00:00Added an answer on May 21, 2026 at 10:23 pm
    Toast.makeText(this, "Service destroyed ...", Toast.LENGTH_LONG).show();
    

    You can’t modify UI from the non-UI thread. Services are never executed on the UI thread. Log this instead of making a Toast.

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

Sidebar

Related Questions

I have created one service in my grails application. in that service 25 methods
I have created one WCF service, in which I am reading the msn whether
I have created one windows service which send an email notifications to users (list
I have created a one-time subscription in SSRS report manager 2008. However I keep
I have created 2 WCF service libraries in a solution. I have also created
I have created one of the software for one organization. But there is also
I have two windows application, one is a windows service which create EventWaitHandle and
I have created one UIImageView Here's code capView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kARROW_CAP_NAME]]; capView.frame
I have created one library project in iphone and my images folder is present
i have created one image but problem is that when i save image from

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.