Question

I am creating an service which is use Service Component ,I want to run the application always in background . Suppose i switch off the mobile and when i on the mobile our application is closed i.e. automatically.

am trying this code

androidManifest.xml

<receiver android:name=".receiver.ConnectionReceiver">
<intent-filter> 
<action android:name="android.intent.action.BOOT_COMPLETED" /> 
</intent-filter> 
</receiver>  

and adding this code in BroadCastreceiver Class update

private class ConnectionReceiver extends BroadcastReceiver{

        private Timer mTimer;
        private TimerTask mTimerTask;
        private long interval;

        @Override
        public void onReceive(Context context, Intent intent) {
             AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
             PendingIntent pi = PendingIntent.getService(context, 0, new Intent(context, ConnectionReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
             am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + interval, interval, pi); 
                {
                calGps();
                }
                }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top