I have use service for collect fixes from network plocation provider. I have not use wacklock, but my app whatever locks device.
I have seen it in Battery Histor for GB, for example:
Screen ON: 2 minutes;
Running: 5 minutes;
Partial wake lock by my app: 10 minutes.
It should be? I need collect location data only when device awake.
This is my sercive:
package com.myapp.service;
import com.myapp.App;
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.location.LocationProvider;
import android.os.IBinder;
public class LocationMonitor extends Service
{
/**********************
* PUBLIC CONSTANTS
**********************/
public static final String ACTION_START = "StartService"; // start action
public static final String ACTION_STOP = "StopService"; // stop action
/**********************
* PRIVATE CONSTANTS
**********************/
private static final long MINIMUM_DISTANCE_CHANGE = 10; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 300 * 1000; // in Milliseconds
/**********************
* PRIVATE VARIBLES
**********************/
private LocationManager sLocationManager; // location manager
/**********************
* SERVICE LIFECYCLE
**********************/
#Override
public void onCreate()
{
super.onCreate();
startService();
}
#Override
public IBinder onBind(Intent intent)
{
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
if (intent != null)
{
if (intent.getAction().equals(ACTION_STOP))
{
stopService();
return START_NOT_STICKY;
}
}
return START_STICKY;
}
private void startService()
{
sLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
sLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE, sNetworkLocationListener);
}
private void stopService()
{
sLocationManager.removeUpdates(sNetworkLocationListener);
stopSelf();
}
/**********************
* LOCATION LISTENERS
**********************/
private LocationListener sNetworkLocationListener = new LocationListener()
{
#Override
public void onLocationChanged(Location location)
{
// store location in db
}
#Override
public void onProviderDisabled(String provider) {}
#Override
public void onProviderEnabled(String provider) {}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
};
/**********************
* STATIC METHODS
**********************/
public static void startService(Context context)
{
Intent newIntent = getServiceIntent(context);
newIntent.setAction(ACTION_START);
context.startService(newIntent);
}
public static void stopService(Context context)
{
Intent newIntent = getServiceIntent(context);
newIntent.setAction(ACTION_STOP);
context.startService(newIntent);
}
}
Related
I have a problem with an activity after minimalising. Everything is going ok when i start an activity and press start button. But when i minimalise activity and again maximalize it, it doesnt respond to my buttons and commands. Anybody know what to do? This is my first android app so i dont know what is going on..
here are my classes :
TrackerService
package sk.tuke.smart.makac.services;
import android.app.Service;
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 java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
public class TrackerService extends Service implements LocationListener {
private Intent commandIntent;
private long duration;
private boolean paused,checkedAfterPause;
private int sportActivity;
private double distance,pace,calories;
private ArrayList<Location> finalPositionList = new ArrayList<Location>();
private LocationManager locationManager;
private static final String TAG = "TrackerService";
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Log.i(TAG,"onStart intent " +intent.getAction());
commandIntent=intent;
checkedAfterPause=true;
if(intent.getAction() == "sk.tuke.smart.makac.COMMAND_START"){
if(intent.getAction() == "sk.tuke.smart.makac.COMMAND_START") {
duration = 0;
}
new Timer().scheduleAtFixedRate(new TimerTask()
{
#Override
public void run() {
if(!paused){
duration++;
Intent intent1 = new Intent();
intent1.setAction("sk.tuke.smart.makac.TICK");
intent1.putExtra("duration", duration);
intent1.putExtra("distance",distance);
sendBroadcast(intent1);
Log.i(TAG,"" + duration);
}
}
}, 1000, 1000);
}else if (intent.getAction() == "sk.tuke.smart.makac.COMMAND_PAUSE"){
paused=true;
locationManager.removeUpdates(this);
}
if(intent.getAction() == "sk.tuke.smart.makac.COMMAND_CONTINUE"){
paused=false;
checkedAfterPause=false;
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,3000,10,this);
}
}
#Override
public void onCreate() {
super.onCreate();
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,3000,10,this);
}
#Override
public void onDestroy() {
locationManager.removeUpdates(this);
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onLocationChanged(Location location) {
finalPositionList.add(location);
Location lastLocation;
double minDistance;
if (finalPositionList.size() != 1 && checkedAfterPause) {
lastLocation = finalPositionList.get(finalPositionList.size() - 2);
minDistance=location.distanceTo(lastLocation);
if(minDistance>=2){
distance += location.distanceTo(lastLocation);
}else{
finalPositionList.remove(finalPositionList.size()-1);
}
}
if(commandIntent.getAction() == "sk.tuke.smart.makac.COMMAND_CONTINUE" && !checkedAfterPause){
Log.i(TAG,"checking distance after pause");
lastLocation = finalPositionList.get(finalPositionList.size() - 2);
minDistance=location.distanceTo(lastLocation);
if(minDistance<=100){
distance += location.distanceTo(lastLocation);
}
checkedAfterPause=true;
}
Log.i(TAG,"locations " + finalPositionList);
Log.i(TAG,"distance = " + distance);
}
#Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
#Override
public void onProviderEnabled(String s) {
}
#Override
public void onProviderDisabled(String s) {
}
public long getDuration(){
return duration;
}
public double getPace(){
return pace;
}
}
SportsActivity
package sk.tuke.smart.makac;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import sk.tuke.smart.makac.helpers.MainHelper;
import sk.tuke.smart.makac.services.TrackerService;
public class StopwatchActivity extends AppCompatActivity {
private static final int MY_PERMISSIONS_REQUEST_FINE_LOCATION = 111;
private static final String TAG = "StopwatchActivity";
private boolean started;
private boolean running;
private boolean paused=false;
private long duration;
private double distance;
private MainHelper helper;
private TextView durationView,distanceView;
private Button startButton,endButton;
private BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction()=="sk.tuke.smart.makac.TICK"){
duration = intent.getLongExtra("duration",duration);
distance = intent.getDoubleExtra("distance",distance);
durationView.setText(helper.formatDuration(duration));
distanceView.setText(helper.formatDistance(distance));
}
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stopwatch);
IntentFilter intentFilter = new IntentFilter("sk.tuke.smart.makac.TICK");
registerReceiver(receiver,intentFilter);
started=false;
running=false;
helper = new MainHelper();
durationView = findViewById(R.id.textview_stopwatch_duration);
distanceView = findViewById(R.id.textview_stopwatch_distance);
startButton = findViewById(R.id.button_stopwatch_start);
endButton = findViewById(R.id.button_stopwatch_endworkout);
if(!canAccessLocation()){
ActivityCompat.requestPermissions(this,
new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_FINE_LOCATION);
}
}
public void toggle(View view){
Intent intent = new Intent(this,TrackerService.class);
started=true;
this.running = !this.running;
if(running && started){
startButton.setText("Stop");
endButton.setVisibility(view.GONE);
if(paused){
intent.setAction("sk.tuke.smart.makac.COMMAND_CONTINUE");
paused=false;
}else
intent.setAction("sk.tuke.smart.makac.COMMAND_START");
}
if(!running && started){
startButton.setText("Continue");
endButton.setVisibility(view.VISIBLE);
intent.setAction("sk.tuke.smart.makac.COMMAND_PAUSE");
paused=true;
}
startService(intent);
}
public void endWorkout(View view){
Intent intent = new Intent(this,TrackerService.class);
intent.setAction("sk.tuke.smart.makac.COMMAND_STOP");
startService(intent);
setContentView(R.layout.activity_workout_detail);
onStop();
}
public void openMaps(View view){
Intent intent = new Intent(StopwatchActivity.this, MapsActivity.class);
startActivity(intent);
}
#Override
protected void onStart() {
super.onStart();
}
#Override
protected void onStop() {
super.onStop();
Intent intent= new Intent(this,TrackerService.class);
stopService(intent);
}
private boolean hasPermission(String perm) {
return(PackageManager.PERMISSION_GRANTED==checkSelfPermission(perm));
}
private boolean canAccessLocation() {
return(hasPermission(Manifest.permission.ACCESS_FINE_LOCATION));
}
}
You aren't creating a connection to the service. You're only starting it, not binding it. So there's no connection to maintain.
It looks like you're trying to do quasi-binding via actions. Don't do that, properly bind the service and avoid a whole raft of problems like this.
My app has two activities that need GPS, so I tried to offload it to a separate class that either activity could use. I found an answer here that looked easy enough
Android - Best way to implement LocationListener across multiple activities
But of course, it's not working for me. I was wondering if anyone can see the issue. I used pretty much exactly the same code, but I got rid of the gps settings dialog.
Here's my GPS class
package fieldlayout.skipmorrow.com.fieldlayout;
import android.app.Activity;
import android.content.Context;
import android.location.LocationManager;
import android.os.Bundle;
import android.location.LocationListener;
import android.location.Location;
import android.util.Log;
/**
* Created by skip on 4/20/2015.
*/
public class GPS {
private IGPSActivity main;
// Helper for GPS-Position
private LocationListener mlocListener;
private LocationManager mlocManager;
private boolean isRunning;
public GPS(IGPSActivity main) {
this.main = main;
// GPS Position
mlocManager = (LocationManager) ((Activity) this.main).getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
// GPS Position END
this.isRunning = true;
Log.i("FieldLayout_GPS", "GPS Object created");
}
public void stopGPS() {
if(isRunning) {
mlocManager.removeUpdates(mlocListener);
this.isRunning = false;
}
Log.i("FieldLayout_GPS", "stopGPS");
}
public void resumeGPS() {
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
this.isRunning = true;
Log.i("FieldLayout_GPS", "resumeGPS");
}
public boolean isRunning() {
return this.isRunning;
}
public class MyLocationListener implements LocationListener {
private final String TAG = MyLocationListener.class.getSimpleName();
#Override
public void onLocationChanged(Location loc) {
GPS.this.main.locationChanged(loc.getLongitude(), loc.getLatitude());
Log.i("FieldLayout_GPS", "onLocationChanged");
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.i("FieldLayout_GPS", "onStatusChanged");
}
#Override
public void onProviderEnabled(String provider) {
Log.i("FieldLayout_GPS", "onProviderEnabled");
}
#Override
public void onProviderDisabled(String provider) {
Log.i("FieldLayout_GPS", "onProviderDisabled");
}
}
}
The interface file
package fieldlayout.skipmorrow.com.fieldlayout;
/**
* Created by skip on 4/20/2015.
*/
public interface IGPSActivity {
public void locationChanged(double longitude, double latitude);
}
And my implementation from my activity
package fieldlayout.skipmorrow.com.fieldlayout;
import android.content.Context;
import android.content.Intent;
public class StartActivity extends ActionBarActivity implements IGPSActivity{
private Location currentLocation;
private GPS gps;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
gps = new GPS(this);
}
#Override
protected void onResume() {
if (!gps.isRunning()) gps.resumeGPS();
super.onResume();
}
#Override
protected void onStop() {
// Disconnecting the client invalidates it.
Log.i("FieldLayout_StartAct", "onStop called. Disconnecting GPS client");
gps.stopGPS();
super.onStop();
}
#Override
public void locationChanged(double longitude, double latitude) {
Log.i("FieldLayout_StartAct", "locationChanged");
currentLocation.setLatitude(latitude);
currentLocation.setLongitude(longitude);
}
}
The only log I am seeing is the creation of the GPS object. None of the other methods in the listener are being executed.
GPS class constructor contains this row:
public GPS(IGPSActivity main) {
this.main = main;
// GPS Position
mlocManager = (LocationManager) ((Activity) this.main).getSystemService(Context.LOCATION_SERVICE);
...
}
And your interface looks like this:
public interface IGPSActivity {
public void locationChanged(double longitude, double latitude);
}
So, the GPS class get an interface, and you want to cast it into an Activity to get a system service from it. That is not going to work.
Change your GPS class a little bit. For example:
public GPS(IGPSActivity main, Activity activity){
mlocManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
...
}
Call this in your activity:
gps = new GPS(this, this);
My Application crashes when gps is off and the back end code searches for the location of the user. I have tried the following code for finding the location of user when gps is off it searches using the internet.
Please suggest something in the following code or any other way
below is my code for the locationservice:
package com.example.myapp;
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;
public class LocationService extends Service implements LocationListener {
protected LocationManager locationManager;
Location location;
private static final long MIN_DISTANCE_FOR_UPDATE = 10;
private static final long MIN_TIME_FOR_UPDATE = 1000 * 60 * 2;
public LocationService(Context context) {
locationManager = (LocationManager) context
.getSystemService(LOCATION_SERVICE);
}
public Location getLocation(String provider) {
if (locationManager.isProviderEnabled(provider)) {
locationManager.requestLocationUpdates(provider,
MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);
return location;
}
}
return null;
}
#Override
public void onLocationChanged(Location location) {
}
#Override
public void onProviderDisabled(String provider) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
#Override
public IBinder onBind(Intent arg0) {
return null;
}
}
When ever I search for getting location I got result to get Location via Location Manager but in a tutorial I have seen that they use LocationRequest to get user Location and I have managed to create a Service that give location based on time
import android.app.Service;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.os.IBinder;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.model.LatLng;
public class LocationTrackerService extends Service implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener, LocationListener {
private LocationClient nLocationClient;
public static boolean serviceStopCheck = true;
private DBHelper nDbHelper;
private int timeForService = 60000;
#Override
public IBinder onBind(Intent intent) {
return null;
}
// #Override
// public int onStartCommand(Intent intent, int flags, int startId) {
// timeForService=Integer.valueOf(intent.getStringExtra("TIME_FOR_SERVICE"))*1000;
// return super.onStartCommand(intent, flags, startId);
// }
#Override
public void onDestroy() {
super.onDestroy();
serviceStopCheck = true;
}
#Override
public void onCreate() {
super.onCreate();
nDbHelper = new DBHelper(this);
nLocationClient = new LocationClient(this, this, this);
nLocationClient.connect();
serviceStopCheck = false;
}
#Override
public void onConnectionFailed(ConnectionResult arg0) {
}
#Override
public void onConnected(Bundle arg0) {
LocationRequest request = LocationRequest.create();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setInterval(timeForService);
request.setFastestInterval(timeForService);
nLocationClient.requestLocationUpdates(request, this);
}
#Override
public void onDisconnected() {
}
#Override
public void onLocationChanged(Location arg0) {
if (!serviceStopCheck) {
LocationItem nLocationItem = new LocationItem(new LatLng(
arg0.getLatitude(), arg0.getLongitude()),
CommonMethods.getCurentTime(),
CommonMethods.getCurentDate());
try {
nDbHelper.insertLocationItem(nLocationItem);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
stopSelf();
}
}
}
So Is better or I have to use LocationManger. Because I think this code is two much easy then using LocationMnager or GPSTracker class provider by some one.
As for me, I have tested that both methods, and I have a conclusion: LocationManager is better, because it uses hardware GPS and it have better accuracy than LocationClient. LocationClient is a part of GooglePlay services, so I think they are using internet coordinates instead of GPS coordinates. But for me the best way is LocationManager, cause it was giving me the best accuracy.
Greg
Here is my New code based on your suggestions. It did not work. I got a bunch of "Just sent a text message with coords" in a row. So it still is not sleeping for 15 seconds.
package com.droid.service;
import java.text.SimpleDateFormat;
import java.util.Calendar;
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.Handler;
import android.os.IBinder;
import android.os.Looper;
public class DroidService extends Service
{
private LocationManager lm;
private LocationListener locationListener;
private Location location = null;
#Override
public IBinder onBind(Intent arg0)
{
return null;
}
// #Override
// public void onCreate()
// {
// super.onCreate();
// initService();
// }
private static final int PERIOD = 15000;
Handler mHandler;
Runnable mRunnable;
#Override
public void onCreate()
{
super.onCreate();
mHandler = new Handler();
mRunnable = new Runnable()
{
public void run()
{
updateNotification();
mHandler.postDelayed(this, PERIOD);
System.out.println("PAUSE FOR 15 SECONDS..!!");
}
};
}
#Override
public void onStart(final Intent intent, final int startId)
{
super.onStart(intent, startId);
mRunnable.run();
}
// private void initService()
// {
// System.out.println("In initService..Droid Service...!!");
// int initialDelay = 15000; // start after 15 seconds
// // int period = 300000; // repeat every 5 minuets
// // int period = 1800000; // repeat every 30 minuets
// int period = 15000; // repeat every 15 seconds for testing
// Timer timer = new Timer();
// TimerTask task = new TimerTask()
// {
// public void run()
// {
// Looper.prepare();
// updateNotification();
// Looper.loop();
// }
// };
// timer.scheduleAtFixedRate(task, initialDelay, period);
// }
protected void updateNotification()
{
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationlistener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
public static class DateUtils
{
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
public static String now()
{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
}
}
private class MyLocationlistener implements LocationListener
{
public void onLocationChanged(Location loc)
{
double lat = loc.getLatitude();
double lon = loc.getLongitude();
String latitude = Double.toString(lat);
String longitude = Double.toString(lon);
String coords = latitude + longitude;
// comment out text message for debug mode
// SmsManager sm = SmsManager.getDefault();
// sm.sendTextMessage("phoneNumber", null, coords, null, null);
System.out.println("Just sent a text message with coords");
}
public void onProviderDisabled(String provider)
{
}
public void onProviderEnabled(String provider)
{
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
}
Here is my code
I get "Just sent a text message with coords" sent like once a second even though my scheduleAtFixedRate is set for 10 seconds.
I got this to work in a normal program, but on the Android platform, they want you to use Looper....and it appears that my code is caught up in this Looper so therefore it is ignoring my scheduleAtFixedRate(10 seconds)
Any help is greatly appreciated.
package com.droid.service;
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.os.Looper;
public class DroidService extends Service
{
private LocationManager lm;
private LocationListener locationListener;
private Location location = null;
#Override
public IBinder onBind(Intent arg0)
{
return null;
}
#Override
public void onCreate()
{
super.onCreate();
initService();
}
private void initService()
{
System.out.println("In initService..!!");
int initialDelay = 15000; // start after 15 seconds
// int period = 300000; // repeat every 5 minuets
// int period = 1800000; // repeat every 30 minuets
int period = 15000; // repeat every 15 seconds for testing
Timer timer = new Timer();
TimerTask task = new TimerTask()
{
public void run()
{
Looper.prepare();
updateNotification();
Looper.loop();
Looper.myLooper().quit();
}
};
timer.scheduleAtFixedRate(task, initialDelay, period);
}
protected void updateNotification()
{
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationlistener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
private class MyLocationlistener implements LocationListener
{
public void onLocationChanged(Location loc)
{
double lat = loc.getLatitude();
double lon = loc.getLongitude();
String latitude = Double.toString(lat);
String longitude = Double.toString(lon);
String coords = latitude + longitude;
// comment out text message for debug mode
// SmsManager sm = SmsManager.getDefault();
// sm.sendTextMessage("phoneNumber", null, coords, null, null);
System.out.println("Just sent a text message with coords");
}
public void onProviderDisabled(String provider)
{
}
public void onProviderEnabled(String provider)
{
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
}
I think the misconception here is not so much that Android wants to use a Looper, but thaty you shouldn't use the Timer for the behavior that you desire. Instead of the Timer you have to manipulate a Looper. I haven't used the Looper directly in a while because there are other components which abstract away a lot of the nuances of it. However I think that Looper.loop() should not return until an outside entity either interrupts your thread or quit's the looper for you. So I don't think that will work, I could be wrong though.
You could use a Handler if you want to create a pulse. A Handler allow you to do work on the Looper thread.
So with the example you have,
private static final int PERIOD = 15000;
Handler mHandler;
Runnable mRunnable;
#Override
public void onCreate() {
super.onCreate();
mHandler = new Handler();
mRunnable = new Runnable() {
public void run() {
updateNotication();
mHandler.postDelayed(this, PERIOD);
}
};
}
I will admit from here on out I am only guessing I know the desired outcome of your application. I am assuming you don't need two way communication as your IBinder is null.
#Override
public void onStart() {
mRunnable.run();
}
// The rest of your code.
..
Try to call initService from onStart().
Basically the best bet for me was to call this onCreate. Now it is doing exactly what I want it to do. Thanks for all your inputs..!! This helped me solve the problem.