I am making an android app to log current user location to my server every few hour. So far I have made a class to give me current user location and i have also been able to send location data to web. I have also been able to register a service in my app to run, even my app has been cleared from background. Now I want to integrate all these, but cant seem to integrate it.
My main activity is
public class MainPage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainpage);
Intent i= new Intent(MainPage.this, RunnerService.class);
this.startService(i);
}
}
and my service is:
public class RunnerService extends Service {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Log.d("SahiyogiHaat", "Service created");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Log.d("SahiyogiHaat", "Service started");
return Service.START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
So where should I make object of my location tracker class to run the service and access user location every 1 hour. In addition to this I tried to implement on reboot broadcast receiver as follows and implement the service from there when user switches on his mobile:
public class MyReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent i= new Intent(context, RunnerService.class);
// potentially add data to the intent
context.startService(i);
}
}
but the service doest start but it says "unfortunately application stopped working", which mean the broadcast has been received but there is some problem. My manifest file is as below: